Users of one of my customer constantly complain that newly created files don’t appear immediately on the network shared folder on Windows Server 2008 R2, but with a long delay, even if they refresh the share folder contents by pressing F5. Regardless of whether a user opens the network share using the UNC path or it is connected as a network mapped drive, new files and folders after they have been copied or created appear only in 1-2 minutes, not immediately. However, if you specify the full name of the file using its UNC path (\\lon-file-srv1\public\new_file.docx), it will open, though will not be visible in the File Explorer.
Thus, at some moments the list of files and folders in the same network shared folder won’t match if viewed on two different computers. It should be noted that user computers are running Windows 7 as the desktop OS.
The matter is that caching began to be used in SMB v2.x for Windows 2008 / Vista (see the table of SMB protocol versions) to reduce traffic and the number of SMB requests between an SMB client and server, and to provide quick access to network shared files and folders (it is quite effective when accessing the network shares using a slow channel or an untenable channel). Thus, Microsoft Redirector component on user computers uses a local cache containing network share metadata. By default the cache is cleared every 10 seconds.
If you face a problem when new files are slow to show up in a network shared folder, you can disable metadata caching for SMB v2 on the clients.
Get-SmbConnection
There are three registry parameters that manage network shares cache settings on the SMB client. Microsoft states that the default values of these keys provide the best performance for most environments. The parameters of SMB2 cache settings are located in the registry key HKLM\System\CurrentControlSet\Services\LanmanWorkstation\Parameters.
- DirectoryCacheLifetime is the lifetime of the shared folder metadata cache (10 seconds by default);
- FileNotFoundCacheLifetime is “File not found” response cache (5 seconds);
- FileInfoCacheLifetime is the time of keeping the cache with the file info (10 seconds).
Thus, the default lifetime of the SMBv2 cache in the network shared folder is 10 seconds. When a client updates the contents of the shared folder, the result of the last update is stored on a client for 10 seconds. When accessing this share, all apps are trying to use this cache first.
If you see that new files are not displayed immediately in the network share, check the value of DirectoryCacheLifetime registry key and replace it with the smaller value (or disable it completely).
To disable caching of the SMB folders, create a DWORD parameter with the name DirectoryCacheLifetime in HKLM\System\CurrentControlSet\Services\LanmanWorkstation\Parameters and change its value to 0. Then restart your computer. In the same way, you can change the values of FileInfoCacheLifetime and FileNotFoundCacheLifetime parameters to 0.
After that all changes in the network shared folder will be immediately displayed on a client (the contents of the folder is refreshed each time it is accessed and the local cache is not used).