我刚刚开始在我的一些 Controller 操作上使用 OutputCache,但我并没有得到我期望的响应。
我已将缓存时间设置为 5 分钟,并且 Expires header 的出现与 Last-Modified header 相同,即发出请求的时间。
这是我目前得到的标题:
Date Thu, 16 Jul 2009 06:35:07 GMT
Server Microsoft-IIS/6.0
X-Powered-By ASP.NET
X-AspNet-Version 2.0.50727
X-AspNetMvc-Version 1.0
Content-Encoding gzip
Cache-Control public, max-age=300
Expires Thu, 16 Jul 2009 06:35:06 GMT
Last-Modified Thu, 16 Jul 2009 06:35:03 GMT
Vary *
Content-Type text/html; charset=utf-8
Content-Length 575
这是我期望的标题:
Date Thu, 16 Jul 2009 06:35:07 GMT
Server Microsoft-IIS/6.0
X-Powered-By ASP.NET
X-AspNet-Version 2.0.50727
X-AspNetMvc-Version 1.0
Content-Encoding gzip
Cache-Control public, max-age=300
Expires Thu, 16 Jul 2009 06:40:06 GMT
Last-Modified Thu, 16 Jul 2009 06:35:03 GMT
Vary *
Content-Type text/html; charset=utf-8
Content-Length 575
关于为什么要这样做的任何想法?
干杯
安东尼
最佳答案
max-age
优先(来自 RFC 2616 ):
We use the term
expires_value
to denote the value of the Expires header. We use the termmax_age_value
to denote an appropriate value of the number of seconds carried by the "max-age" directive of the Cache-Control header in a response (see section 14.9.3).The max-age directive takes priority over Expires, so if max-age is present in a response, the calculation is simply:
freshness_lifetime = max_age_value
Otherwise, if Expires is present in the response, the calculation is:
freshness_lifetime = expires_value - date_value
所以客户端应该像你期望的那样使用缓存版本。
关于.net - ASP.NET MVC : OutputCache and http headers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1135807/