Oct 232014
 

Screen Shot 2014-10-23 at 16.17.09Currently I’m busy building several automated workflows that run on our flow:rage Video Storage System and that move files and directories from A to B while processing them in some way.

During qualifying this workflows for production we discovered that moved items were not immediately visible for Windows clients connected using SMB. Sometimes it took several minutes for the files and directories to show up. Even manually refreshing the parent folder did not help. Linux and OS X clients were not affected by this issue and so it was clear that this had to be a client side caching problem.

My google-fu helped me to find the TechNet article SMB2 Client Redirector Caches Explained that explains the Windows SMB2 Cache and it’s configuration options. Based on the I created the following .reg file [download]:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\LanmanWorkstation\Parameters]
"DirectoryCacheLifetime"=dword:00000000

This configuration change disables the client side directory content cache. That means that file and directory changes are immediately visible for the client. This was exactly what I needed to solve my issue. However be aware that this change causes the client to contact the server more frequently.

  5 Responses to “How to disable SMB client-side caching”

  1. Thanks for sharing this, you may have just solved one of our major issues with our product written in Visual Foxpro 9.0

    • same here!! After the Windows 1803 update, people started having issues with our software. This resolved it for them! set-smbclientconfiguration -directorycachelifetime 0 and -fileinfocachelifetime 0

  2. Hi,
    To disable SMB2 caching you can (must) also disable FileInfoCacheLifetime and FileNotFoundCacheLifetime. We use the following PowerShell snippet in our deployments:

    `$Name1 = “DirectoryCacheLifetime”
    $Name2 = “FileInfoCacheLifetime”
    $Name3 = “FileNotFoundCacheLifetime”
    $value = “0”
    New-ItemProperty -Path $registryPath -Name $name1 -Value $value -PropertyType DWORD -Force | Out-Null
    New-ItemProperty -Path $registryPath -Name $name2 -Value $value -PropertyType DWORD -Force | Out-Null
    New-ItemProperty -Path $registryPath -Name $name3 -Value $value -PropertyType DWORD -Force | Out-Null`

  3. […] If i mount the share on the Linux machine itself i can see the full content. First i thought Windows uses some cache magic, so i disabled caching: https://bogner.sh/2014/10/how-to-disable-smb-client-side-caching/ […]

  4. Thanks a lot for sharing, it solve my mistake.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)