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.SetSlidingExpiration(true);
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetExpires(DateTime.Now.AddDays(28));
Response.Cache.SetMaxAge(new TimeSpan(672, 0, 0));
Response.Cache.SetLastModified(lastModified);
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?