Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output caching still adding Cache-Control:no-cache even when it is disabled

Tags:

iis-7

Background

A customer is running our web app. over HTTPS and are running into the (fairly well know) IE8 "file cannot be written to cache" error when they try to view a PDF/Excel/word file because the response contains the HTTP Cache-Control:no-cache directive. The thing is, it is not our app (or its config) that is adding this directive.

After a bit of investigating I discovered that the IIS7 page output caching feature can also add this header, for example

<caching enabled="false" enableKernelCache="false">
    <profiles>
        <add extension=".htm" policy="CacheUntilChange" kernelCachePolicy="CacheUntilChange" />
    </profiles> 
</caching>

will have the effect of adding Cache-Control:no-cache, private to response headers.

My Question

But the surprising (IMO) thing is that even when you supposedly disable the feature (see in my config snippet above that enabled="false"), the response headers are still being sent with Cache-Control:no-cache, private.

Am I being stupid to be surprised by this (I guess I probably am)?

like image 809
Chris Fewtrell Avatar asked Nov 17 '10 13:11

Chris Fewtrell


People also ask

When the value of cache-control is set to no-cache ie disable cache?

cache-control: no-cacheThis token is changed on the origin server whenever the resource is updated. When a user returns to a page with a 'no-cache' resource, the client will always have to connect to the origin server and compare the ETag on the cached resource with one on the server.

How do you ignore cache-control?

If specified, HTTP request cache-control headers are ignored for caching decisions. This option available under Web Sites > Traffic management > Caching > Edit the service and set the value of 'Ignore Request Headers' to Yes.

What does cache-control no-cache mean?

Cache-Control: No-Cache The no-cache directive means that a browser may cache a response, but must first submit a validation request to an origin server.


2 Answers

What effectively got rid of no-cache for me was adding location="Any" to the add element, which instead writes Cache-Control:public:

<caching enabled="false" enableKernelCache="false">
    <profiles>
        <add extension=".htm" ... location="Any" />
    </profiles> 
</caching>

In the absence of the location attribute, IIS defaults to Cache-Control:no-cache. Other possible values are Client, Downstream, Server, or ServerAndClient. Details here.

like image 92
Todd Menier Avatar answered Nov 04 '22 19:11

Todd Menier


You're not alone: http://forums.iis.net/t/1152306.aspx

We also had the same problem. I haven't found any documentation about this "feature" so I'm assuming it is a bug.

We decided to just remove the caching tag and use only the clientCache tag instead.

like image 29
jColeson Avatar answered Nov 04 '22 17:11

jColeson