How to disable IIS from caching static files (PNG, JS, HTML, etc ))

Source: Internet
Author: User
Tags metabase

Disable IIS from caching static files (PNG, JS, HTML, etc.) Background:
To improve the performance of IIS, static files such as JS, HTML, GIF, and PNG are cached internally by default. This cache is in the memory of the IIS Process on the server. To a large extent, IIS can improve the access performance of static files. Under normal circumstances, as long as the static files update IIS, the cache will be updated. However, if many static files are updated, the cache may not be updated.

Detours:
I have encountered a scenario where the server cyclically updates tens of thousands of Stock Market images, and IIS also caches the images. Due to the high update frequency, there are many files, the IIS cache files cannot be updated after dozens of minutes.

In this case, the browser caches the file, so it sets the HTTP header: cache-control: No-cache in the IIS directory, but it does not help, the browser requests the server to get the status code 200, which indicates that the browser indeed obtains new content from the server rather than reading the local cache of the browser.

How to disable IIS from caching static files (PNG, JS, HTML, etc ):
Setting the HTTP header to prevent the browser from caching does not work in this scenario, because the cache does not appear on the client, but on the IIS server; to solve the problem, you must start with IIS by configuring metabase. XML files prohibit IIS from caching static files in the corresponding directory.

1. First, you must set IIS to allow you to edit the metabase. xml file during runtime.

Open IIS, then open the IIS properties page, and check the "Allow to directly edit the configuration database" option.

2. Enter notepad c: \ windows \ system32 \ inetsrv \ metabase. XML to open the IIS configuration file.

3. Search for the name of the virtual directory in which the cache is disabled and find the configuration section similar to the following:
<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 the md_vr_no_cache = "1" attribute in the iiswebvirtualdir configuration section.

4. Save the configuration file and restart IIS.

To disable IIS cache for all sites on the server, you can modify the registry:
Edit the disablestaticfilecache value in the registry. 0 indicates enabled, 1 indicates disabled, and the key value is located at: HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ inetinfo \ parameters.
If the key does not exist, you can create a new one.

Note:

Normally, you do not need to disable IIS static file caching. IIS automatically updates the cache based on the modification time of the static file. IIS caching is only required when you encounter a situation. There is no relationship between IIS cache and HTTP cache headers. Adding cache headers to IIS cannot clear IIS cache for static files.

Please respect the work of the author, repost please keep the link to yukai technical blog

Disable IIS from caching static files (PNG, JS, HTML, etc.) Background:
To improve the performance of IIS, static files such as JS, HTML, GIF, and PNG are cached internally by default. This cache is in the memory of the IIS Process on the server. To a large extent, IIS can improve the access performance of static files. Under normal circumstances, as long as the static files update IIS, the cache will be updated. However, if many static files are updated, the cache may not be updated.

Detours:
I have encountered a scenario where the server cyclically updates tens of thousands of Stock Market images, and IIS also caches the images. Due to the high update frequency, there are many files, the IIS cache files cannot be updated after dozens of minutes.

In this case, the browser caches the file, so it sets the HTTP header: cache-control: No-cache in the IIS directory, but it does not help, the browser requests the server to get the status code 200, which indicates that the browser indeed obtains new content from the server rather than reading the local cache of the browser.

How to disable IIS from caching static files (PNG, JS, HTML, etc ):
Setting the HTTP header to prevent the browser from caching does not work in this scenario, because the cache does not appear on the client, but on the IIS server; to solve the problem, you must start with IIS by configuring metabase. XML files prohibit IIS from caching static files in the corresponding directory.

1. First, you must set IIS to allow you to edit the metabase. xml file during runtime.

Open IIS, then open the IIS properties page, and check the "Allow to directly edit the configuration database" option.

2. Enter notepad c: \ windows \ system32 \ inetsrv \ metabase. XML to open the IIS configuration file.

3. Search for the name of the virtual directory in which the cache is disabled and find the configuration section similar to the following:
<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 the md_vr_no_cache = "1" attribute in the iiswebvirtualdir configuration section.

4. Save the configuration file and restart IIS.

To disable IIS cache for all sites on the server, you can modify the registry:
Edit the disablestaticfilecache value in the registry. 0 indicates enabled, 1 indicates disabled, and the key value is located at: HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ inetinfo \ parameters.
If the key does not exist, you can create a new one.

Note:

Normally, you do not need to disable IIS static file caching. IIS automatically updates the cache based on the modification time of the static file. IIS caching is only required when you encounter a situation. There is no relationship between IIS cache and HTTP cache headers. Adding cache headers to IIS cannot clear IIS cache for static files.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.