如何在客户端和客户端进行缓存当 VaryByParam != "none" 时服务器?

发布于 2024-08-19 22:11:01 字数 1115 浏览 7 评论 0 原文

我正在寻找一种在客户端和服务器上缓存页面的方法,同时通过查询字符串参数“版本”改变服务器的输出缓存。

有了这个标签:

<%@ OutputCache Duration="10" Location="Any" VaryByParam="none" %>

我得到了这些标题:

HTTP/1.1 200 OK
Cache-Control: public
Content-Type: text/html; charset=utf-8
Expires: Wed, 03 Feb 2010 02:29:24 GMT
Last-Modified: Wed, 03 Feb 2010 02:29:14 GMT
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.21006
X-Powered-By: ASP.NET
Date: Wed, 03 Feb 2010 02:29:14 GMT
Content-Length: 2364

这正是我在客户端想要的,但在服务器端它不会因“版本”而变化。

同时,使用这个标签:

<%@ OutputCache Duration="10" Location="Any" VaryByParam="Version" %>

我得到这些标头:

HTTP/1.1 200 OK
Cache-Control: public, max-age=4
Content-Type: text/html; charset=utf-8
Expires: Wed, 03 Feb 2010 02:28:29 GMT
Last-Modified: Wed, 03 Feb 2010 02:28:19 GMT
Vary: *
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.21006
X-Powered-By: ASP.NET
Date: Wed, 03 Feb 2010 02:28:25 GMT
Content-Length: 2352

这正是我在服务器端想要的,但是“Vary:*”标头迫使浏览器在每个请求时重新加载页面。

有什么方法可以在客户端和服务器端同时根据参数进行缓存吗?

I'm looking for a way to cache a page at both the client and the server while varying the server's output cache by a querystring parameter "Version".

With this tag:

<%@ OutputCache Duration="10" Location="Any" VaryByParam="none" %>

I get these headers:

HTTP/1.1 200 OK
Cache-Control: public
Content-Type: text/html; charset=utf-8
Expires: Wed, 03 Feb 2010 02:29:24 GMT
Last-Modified: Wed, 03 Feb 2010 02:29:14 GMT
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.21006
X-Powered-By: ASP.NET
Date: Wed, 03 Feb 2010 02:29:14 GMT
Content-Length: 2364

This does exactly what I want on the client side, but on the server side it doesn't vary by "Version".

Meanwhile, with this tag:

<%@ OutputCache Duration="10" Location="Any" VaryByParam="Version" %>

I get these headers:

HTTP/1.1 200 OK
Cache-Control: public, max-age=4
Content-Type: text/html; charset=utf-8
Expires: Wed, 03 Feb 2010 02:28:29 GMT
Last-Modified: Wed, 03 Feb 2010 02:28:19 GMT
Vary: *
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.21006
X-Powered-By: ASP.NET
Date: Wed, 03 Feb 2010 02:28:25 GMT
Content-Length: 2352

This does exactly what I want on the server side, but the "Vary: *" header forces the browser to reload the page on every request.

Is there any way to get caching on both the client and server side while varying by a parameter?

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

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

发布评论

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

评论(1

迷你仙 2024-08-26 22:11:01

找到它:

protected void Page_Load(object sender, EventArgs e)
{
  Response.Cache.SetOmitVaryStar(true);
}

更多信息在这里:http://support.microsoft.com/kb/836868

据说 ASP.NET 4 beta 2 已修复此问题(请参阅 http ://www.asp.net/learn/whitepapers/aspnet4/writing-changes/#_TOC10),但从 VS 2010 RC 开始,它似乎仍然损坏。

Found it:

protected void Page_Load(object sender, EventArgs e)
{
  Response.Cache.SetOmitVaryStar(true);
}

More info here: http://support.microsoft.com/kb/836868

Supposedly this has been fixed for ASP.NET 4 beta 2 (see http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes/#_TOC10) but it still seems broken as of VS 2010 RC.

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