IIS7 Web.Config Caching - what are the differences here, and how does it all come together?
Asked Answered
M

2

10

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.

Markowitz answered 30/1, 2011 at 4:54 Comment(2)
Chase, were you able to find out anymore information on this? StaticContent seems to be mucking with my caching profiles and I'm curious about any information that could be shared.Kissiah
After I asked, I sorta forgot about it. I would like a good canonical answer.Markowitz
H
4

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.

Harrold answered 24/9, 2013 at 15:50 Comment(1)
If you specify location="ServerAndClient" in the add extension=".png" tag, you can cache on the client as well as the serverStaffard
M
1

I've noticed that people often confuse the things above and write articles where recommend things as in the first block, i.e. output caching for static resources

Output caching:

Output caching is unnecessary for static files, such as HTML, JPG, or GIF files, and can cause more memory overhead for dynamic ASP.NET or PHP pages that read from a database that changes frequently

Thus

<add extension=".png" ../>
<add extension=".jpeg" ../>
etc.

is useless at least when you don't have ashx http handler for .png or .jpeg etc.

Magallanes answered 23/8, 2016 at 12:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.