Configuring cache expiration on IIS 7
As you may be aware of we used something called wildcard mappings on IIS 6 to be able to trap all requests inside EPiServer CMS, that also meant that we took care of delivery of static files even outside the VPP-folders. So, for example the expiration time for your CSS-files in the templates folder was configured by this element located in the root of web.config:
1: <staticFile expirationTime="12:0:0" />
But, since we use the new integrated pipeline in IIS 7 we dropped the wildcard mapping and we can let IIS itself take care of all static files. That also means that there are other settings that controls the cache expiration for files outside of VPP-folders. Add this setting under the <system.webServer>-element to add a 1-day expiration on all static files delivered by IIS 7:
1: <staticContent>
2: <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00"></clientCache>
3: </staticContent>
What's even better in IIS 7 is that you can add profiles for kernel caching (and output caching for that matter). This section adds kernel caching on often requested files for a short period of time, but remember that this setting will affect ALL content delivered from IIS including files from a VPP-folder:
1: <caching>
2: <profiles>
3: <add extension=".gif" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
4: <add extension=".png" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
5: <add extension=".js" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
6: <add extension=".css" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
7: <add extension=".jpg" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
8: <add extension=".jpeg" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
9: </profiles>
10: </caching>
IIS 7 actually has 3 different output caches that do almost the same thing: the ASP.NET output cache, the IIS 7 user-mode output cache and the IIS 7 kernel-mode output cache. Both IIS output caches are controlled using the caching profiles and the ASP.NET output cache is controlled by ASP.NET as before. But looking a bit closer on the ASP.NET Output Cache you will see that it actually under some circumstances enables kernel caching using some direct API calls.
13 March 2009