gpt4 book ai didi

asp.net - 如何缓存 ASP.NET 网站以获得更好的性能

转载 作者:行者123 更新时间:2023-12-01 22:10:59 25 4
gpt4 key购买 nike

我是一名网页设计师,通常设计不需要更新的企业网站。所以我想将输出缓存一天。我怎样才能做到这一点?

此外,任何有关在慢速服务器上提高 asp.net 性能的建议都被接受。

最佳答案

请注意,ASP.NET 缓存有一个 bug从1.0开始,可以有效禁用客户端缓存。
这就是为什么 HttpCachePolicy.SetOmitVaryStar()后来添加了方法作为解决方法。开发者应该使用它,但不幸的是,似乎很少有人知道上述方法。
作为响应,ASP.NET 4.0 中的行为发生了更改,如 ASP.NET 4 Breaking Changes list 中详细说明。 :

In ASP.NET 1.0, a bug caused cached pages that specified Location="ServerAndClient" as an output–cache setting to emit a Vary:* HTTP header in the response. This had the effect of telling client browsers to never cache the page locally.

In ASP.NET 1.1, the System.Web.HttpCachePolicy.SetOmitVaryStar method was added, which you could call to suppress the Vary:* header. This method was chosen because changing the emitted HTTP header was considered a potentially breaking change at the time. However, developers have been confused by the behavior in ASP.NET, and bug reports suggest that developers are unaware of the existing SetOmitVaryStar behavior.

In ASP.NET 4, the decision was made to fix the root problem. The Vary:* HTTP header is no longer emitted from responses that specify the following directive:

<OutputCache Location="ServerAndClient" %>

As a result, SetOmitVaryStar is no longer needed in order to suppress the Vary:* header.

In applications that specify Location="ServerAndClient" in the @ OutputCache directive on a page, you will now see the behavior implied by the name of the Location attribute's value – that is, pages will be cacheable in the browser without requiring that you call the SetOmitVaryStar method.

If pages in your application must emit Vary:*, call the AppendHeader method, as in the following example:

HttpResponse.AppendHeader("Vary","*");

Alternatively, you can change the value of the output caching Location attribute to "Server".

关于asp.net - 如何缓存 ASP.NET 网站以获得更好的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2624181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com