开发者

Does the output cache respect response headers?

I'm considering using the ASP.NET output cache to improve the performance of my custom HTTP handler.

If I set an expiry header in the response, will the output cache be intelligent enough to cache the response accordingly? Or do I need to manually create an appropriate CacheDependency?

If I gzip the response and set the Content-Encoding header, will the output cache be smart enough t开发者_如何学JAVAo prevent the response being double-gzipped if dynamic compression is turned on? What happens if the output cache has a gzipped version and a client that doesn't accept gzip requests the resource?


You can set the output cache to cache content relative to accept headers, not response headers. From this walkthrough on IIS 7.0 caching:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <directoryBrowse enabled="true" />
        <caching>
            <profiles>
                <add extension=".jpg" policy="CacheForTimePeriod"
                duration="00:00:10" varyByHeaders="Accept-Language" />
            </profiles>
        </caching>                  
  </system.webServer>
</configuration>

Using this configuration, the output cache will cache a different value for each language that user agent's ask for. You could add "Accept-Encoding" to the varyByHeaders to cache gzipped and non-gzipped versions of the same resource.

As for expiry headers, as far as I can tell the output cache doesn't take any notice of them. You have to set the output cache expiry and the expiry HTTP header separately - after all there's no guarantee that you would want to use the same policy for both.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜