ASP.NET MVC:OutputCache 和 http 标头

发布于 2024-07-29 02:01:45 字数 1204 浏览 3 评论 0原文

我刚刚开始在一些控制器操作上使用 OutputCache,但没有完全得到我期望的响应。

我已将缓存时间设置为 5 分钟,并且 Expires 标头与 Last-Modified 标头(发出请求的时间)相同。

这是我当前得到的标题:

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

关于为什么要这样做的任何想法?

干杯 安东尼

I have just started using OutputCache on some of my controller actions and I am not quite getting the response I would expect.

I have set the cache time to 5 minutes and the Expires header is coming up the same as the Last-Modified header which is the time that the request was made.

This is the header I am currently getting:

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

This is the header I would expect:

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

Any ideas on why it would be doing this?

Cheers
Anthony

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情徒 2024-08-05 02:01:45

max-age 优先(来自 RFC 2616):

我们使用术语expires_value
表示 Expires 的值
标头。 我们使用这个术语
max_age_value 表示
的数量的适当值
“max-age”携带的秒数
Cache-Control 标头的指令
在响应中(参见第 14.9.3 节)。

max-age指令优先
超过过期时间,因此如果 max-age 存在
在响应中,计算为
简单地说:

 freshness_lifetime = max_age_value  
  

否则,如果 Expires 是
出现在响应中,
计算公式为:

 freshness_lifetime = 过期值 - 日期值 
  

所以客户端应该按照你的预期使用缓存的版本。

max-age takes precedence (from RFC 2616):

We use the term expires_value to
denote the value of the Expires
header. We use the term
max_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

So the client should use the cached version as you expect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文