IIS 7 and Above
IIS Output Caching removes max-age and expires response headers
Last post Mar 07, 2018 08:57 AM by Yuk Ding
Feb 07, 2018 09:03 AM|martin-s|LINK
We run a relatively high-traffic site on IIS 10 and have recently been setting up output caching to improve performance on static and static dynamic (resized images for instance) resource files.
The default IIS settings don't appear to be very useful for large websites with footprints of tens of thousands of files, so we tweaked the configuration to reflect some lessons we learned elsewhere online. These may be useful to diagnose the problem, or
just for someone else looking to optimise:
Updating the registry setting to define how long files are kept in the cache using HKLM\System\CurrentControlSet\services\InetInfo\Parameters\ObjectCacheTTL updated to 21600 (6 hours)
Likewise, increasing the MaxCachedFileSize to 6291456 (6 MB in bytes)
Updating httpCompression maxDiskSpaceUsage="2048" (mb) in applicationhost.config
Setting the app pool timeout to 0, and start mode to always running
Setting <serverRuntime frequentHitTimePeriod="12:00:00" frequentHitThreshold="2" /> in applicationhost.config so that output caching kicks in on the second request for any file in a 12 hour period
Adding extension profiles in web.config for .jpg, .png, .gif, .mp4, .css, .js, .woff, .ttf, etc. with policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" varyByQueryString="v" location="Any" (location=any to remove the cache-control: no-cache header
And in IIS, turning on keep-alive and setting expire web content to 28 days using http response headers > set common headers
In our MVC image resizer, we set:
Response.Cache.SetMaxAge(new TimeSpan(672, 0, 0));
Having recycled the app pool to clear the cache, the first hit on a file returns all of the correct headers. But after the second hit, when IIS output caching has kicked in, the expires, last modified and max-age headers all disappear.
Does anyone have any ideas about why this is the case?
Feb 13, 2018 08:50 AM|Yuk Ding|LINK
The max-age should belong to the client cache and maybe IIS will override it. What about use the http response header->set common header.
Feb 13, 2018 09:02 AM|martin-s|LINK
I am using set common headers already - I did mention that in my post :)
Mar 07, 2018 08:57 AM|Yuk Ding|LINK
How did you set the response common header expire web content time? You could only find the max-age header when you clean the browser cache and access the static content first time. I can still see the max-content even I enable either the user mode output
caching or kernel cache output caching. So if you clean the browser cache and you could see the max-age header, this is how IIS client side cache work.
Just keep in mind that ,the common header define the client cache and it should have nothing to do with the server side output caching.