How to disable IIS cache static files (png, js, html, etc.)

  

prohibit IIS cache static files (png, js, html, etc.) Background:

IIS to improve performance, by default will be static The files js, html, gif, png, etc. do internal caching, which is in the memory of the server iis process. IIS does this to a large extent to improve the access performance of static files. Under normal circumstances, as long as the static file is updated, IIS will also update the cache. However, if there are many static files updated, there may be cases where the cache is not updated.

Detour:

I have encountered such a scenario, the server cyclically updates tens of thousands of stock quotes, IIS will also cache the images, due to the high frequency of updates, many files, There have been cases where the IIS cache file could not be updated for more than a few minutes.

At this time, the intuition is that the browser caches the file, so the Http header is set in the IIS directory: Cache-Control: no-cache, but it does not help, the browser requests the server to get the status number is 200, this can indicate that the browser did get new content from the server side instead of reading the browser local cache.

How to disable IIS to cache static files (png, js, html, etc.):

The method of setting the Http header to prevent the browser from caching is not feasible in this scenario, because the cache is not The client appears, but appears on the IIS server; so the problem needs to start from IIS itself, by configuring the Metabase.xml file to prohibit IIS from caching the static files in the corresponding directory.

1. First need to set IIS to allow the runtime to edit the Metabase.xml file

Open IIS, then open the IIS property page, check the "Allow direct editing of the configuration database" option < Br>

2. Enter notepad c:\\WINDOWS\\system32\\inetsrv\\MetaBase.xml in the run to open the IIS configuration file

3. Search for the virtual directory name to be cached in the file. Similar to the following configuration section

<IIsWebVirtualDir Location="/LM/W3SVC/1832041641/root/inc"
AccessFlags="AccessRead |  AccessScript"
AppFriendlyName="inc"
AppIsolated="2"
AppRoot="/LM/W3SVC/1832041641/Root/inc"
DirBrowseFlags="DirBrowseShowDate |  DirBrowseShowTime |  DirBrowseShowSize |  DirBrowseShowExtension |  DirBrowseShowLongDate |  EnableDefaultDoc"
Path="D:\\publish\\inc"
>
</IIsWebVirtualDir>

Add MD_VR_NO_CACHE=”1” attribute in the IIsWebVirtualDir configuration section

4. Save the configuration file and restart IIS.

If you want to configure all the sites on the server, disable IIS cache by modifying the registry:

Edit DisableStaticFileCache in the registry Value, 0 is enabled, 1 is disabled, the key value is located at: HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\InetInfo\\Parameters

If the key does not exist, it can be created.

Notes :

Under normal circumstances, we do not need to disable IIS's static file cache. iis will automatically update the cache automatically according to the modification time of the static file; it is only necessary to disable IIS cache if you encounter extreme conditions. IIS There is no relationship between the cache and the Http cache related header. There is no way to clear the IIS cache of static files by adding a cache header to IIS.

Copyright © Windows knowledge All Rights Reserved