In IIS 7.5, when I don't have Output Caching enabled, my php script successfully sets browser caching in the Cache-Control header:
Cache-Control: max-age=43200,public
Content-Type: text/html
Expires: Wed, 30 May 2012 22:15:18 GMT
Server: Microsoft-IIS/7.5
X-Powered-By: PHP/5.4.3
Date: Wed, 30 May 2012 10:15:18 GMT
Connection: close
Content-Length: 5105
However, if I enable Output Caching for .php files, I get the following header:
Cache-Control: no-cache,max-age=43200,public
Content-Type: text/html
Expires: Wed, 30 May 2012 22:25:34 GMT
Server: Microsoft-IIS/7.5
X-Powered-By: PHP/5.4.3
Date: Wed, 30 May 2012 10:25:34 GMT
Connection: close
(notice "no-cache" is added to the Cache-Control before my php script's work)
There is no way, I've found, to prevent "no-cache" from being added to the Cache-Control key, if Output caching is enabled for a file type. I've tried to do it in the web.config file:
<customHeaders>
<remove name="X-Powered-By" />
<remove name="Cache-Control" />
<add name="Cache-Control" value="public" />
</customHeaders>
That doesn't work. Why must this be so mutually exclusive? I'd like to have both Output Caching and Browser Caching enabled.
Unfortunately the IIS Manager interface does not allow you to use all features that are supported by the output caching module. One of these features is to set the cache location that indirectly controls the cache-control header. You have to manually edit your web.config to change it. The syntax is like:
<caching>
<profiles>
<add extension=".php" ..... location="Any" />
</profiles>
</caching>
The <add />
tag will have more option depending on how you want your caching to work. The important part is to add the location="..."
attribute. The following values are supported and they control the cache-control header as follows:
Any
or Downstream
= public
ServerAndClient
or Client
= private
None
or Server
or empty = no-cache
As the location
attribute is absent by default, IIS will by default send a Cache-Control: no-cache
header when output caching is enabled. More information about output caching and the supported features can also be found at: Response caching in IIS7
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