2

It's common that Web.config file for an Asp.Net (MVC or not) web application has two directives for caching under system.webServer section:

<staticContent>
    <clientCache cacheControlMaxAge="07.00:00:00" cacheControlMode="UseMaxAge" />
</staticContent>

This one sets the cache control for all static contents to Max-Age: (Now+7Days)

There is also this directive under the same section:

<caching>
    <profiles>
        <add extension=".jpg" location="Any" policy="CacheForTimePeriod" duration="7.00:00:00" kernelCachePolicy="CacheUntilChange" />
    </profiles>
</caching>

This directive sets the cache headers for .jpg files to expires: 7 days and enables caching for all locations (proxy, browser etc...)

What I don't get is, which directive overrides the other? If I omit the profile for .jpg, will it take the clientCache directive's values? (Assuming it's handled by the static file handler)

Also what does "kernelCachePolicy" do actually?

Tequilalime
  • 611
  • 9
  • 29

1 Answers1

1

First of all, this parametres are instructions to the IIS on how to hold the cache.

The static Content cache, make the IIS, automatically add a client side header, and says to the browser to keep the content on their cach and for how long time.

Static content is the content that is not change, like images.

<staticContent>
    <clientCache .... />
</staticContent>

The second cache you mention is the server side cache. Its better to use if for dynamica made pages. Its hold the rendered page on memory and give it from there when its asked.

<caching>
    <profiles>
        <add .... />
    </profiles>
</caching>

You can read more here : What are difference between IIS (Dynamic and Static) cache,OutPutCache and browser cache

Also on IIS web site.
http://www.iis.net/configreference/system.webserver/staticcontent/clientcache
http://www.iis.net/configreference/system.webserver/caching

Community
  • 1
  • 1
Aristos
  • 66,005
  • 16
  • 114
  • 150
  • Thank you for the answer @Aristos. I assume this means that they don't interact with each other (or override one another). as MVC does not have an extension, outputCache is the go to caching for it and cache profiles are for exceptional situations. – Tequilalime Sep 19 '14 at 17:30
  • @Alaminut yes, they do not override one another. My personal opinion is to use the static content only cache setup on web.config, and use asp.net programming for the dynamic cache, so you can control it programmatically. – Aristos Sep 19 '14 at 19:19