In IIS7 I've got the ability to set caching options. These options are added to my web.config as such...
<caching maxCacheSize="262144">
<profiles>
<add extension=".png" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="00:00:30" />
<add extension=".jpeg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="00:00:30" />
<add extension=".jpg" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="00:00:30" />
<add extension=".css" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="00:00:30" />
<add extension=".js" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" duration="00:00:30" />
</profiles>
</caching>
However, I've also got the following for "caching"
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="90.00:00:00" />
<remove fileExtension=".js" />
<mimeMap fileExtension=".js" mimeType="text/javascript" />
</staticContent>
What are the differences between these two configs? They are both nested in the <system.webServer>
tag, so they're both valid for IIS7.
Also, what is the right approach when using these? I currently only use this is my static assets folder. I don't use this caching on anything else.
Thanks in advance.
The IIS output caching feature targets semi-dynamic content. It lets you cache static responses for dynamic requests and increase scalability. Note that not every dynamic page can take advantage of the output cache.
At run time, ASP.NET uses the Web. Config files to hierarchically compute a unique collection of configuration settings for each incoming URL request. These settings are calculated only once and then cached on the server.
IIS Kernel Mode Caching Rules The IIS output cache supports two cache policies. The regular output cache policy takes advantage of a cache that resides in an IIS worker process. The other cache policy is a kernel mode cache policy, in which case the cache resides in HTTP. SYS, a kernel-mode driver.
The main difference is that
the first is for server-side caching of dynamic output such as aspx pages (basically keeps the page output in memory for subsequent requests). As @artem-vertiy's answer points out, using it for static content makes no sense.
the second one is 'internet-side' : it is implemented by writing standard response headers, it tells both client browsers and public proxies how to manage cached files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With