简体   繁体   English

我的asp.net mvc Web应用程序中的OutputCache设置。 多种语法防止缓存

[英]OutputCache setting inside my asp.net mvc web application. Multiple syntax to prevent caching

I am working on an asp.net MVC web application and I need to know if there are any differences when defining the OutputCache for my action methods as follow:- 我正在处理一个asp.net MVC Web应用程序,我需要了解在为我的操作方法定义OutputCache时是否存在任何差异,如下所示:

[OutputCache(Duration = 0, Location = OutputCacheLocation.Client, VaryByParam = "*")]

VS VS

[OutputCache(NoStore = true, Duration = 0, Location="None", VaryByParam = "*")]

VS VS

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]

Will all the above three setting prevent caching the data , or each on have different meaning ? 以上三个设置是否会阻止缓存数据,或者每个都有不同的含义?

Second question what is the main difference between defining duration=0 & NoStore=true ? 第二个问题是,定义duration=0NoStore=true之间的主要区别是什么? will both of them prevent caching ? 它们都可以防止缓存吗? Thanks 谢谢

The NoStore property is used to inform proxy servers and browser that they should not store a permanent copy of the cached content by setting Cache-Control: no-store within the request header. NoStore属性用于通过在请求标头中设置Cache-Control: no-store来通知代理服务器和浏览器它们不应存储缓存内容的永久副本。

Duration simply specifies how long the content of the controller action should be cached, eg 10seconds. 持续时间仅指定应将控制器操作的内容缓存多长时间,例如10秒。 This will set the Cache-Control: max-age to >= 0. And also sets the Expires header to a valid timestamp. 这会将Cache-Control: max-age为> =0。并且还将Expires标头设置为有效时间戳。

To your initial question, no, the three variations do not have the same meaning. 对于您最初的问题,不,这三个变体的含义不同。

[OutputCache(Duration = 0, Location = OutputCacheLocation.Client, VaryByParam = "*")]

create a cache-header like this 创建一个这样的缓存头

Cache-Control: private, max-age=0
Expires: Fri, 03 Jan 2014 12:32:15 GMT

[OutputCache(NoStore = true, Duration = 0, Location="None", VaryByParam = "*")]

creates the following cache-header: 创建以下缓存头:

Cache-Control: no-cache, no-store
Pragma: no-cache
Expires: -1

This is basically what you want to see if you want to prevent caching by all means. 如果要通过某种方式防止缓存,基本上就是要查看的内容。 VaryByParam is optional (at least in MVC5) and the default is "*" anyways, so you can simply use [OutputCache(NoStore = true, Location = OutputCacheLocation.None)] instead. VaryByParam是可选的(至少在MVC5中),并且默认值始终为“ *”,因此您可以简单地使用[OutputCache(NoStore = true, Location = OutputCacheLocation.None)]


[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]

even creates a public cache control... 甚至创建一个公共缓存控件...

Cache-Control: public, no-store, max-age=0
Expires: Fri, 03 Jan 2014 12:36:38 GMT

There is a good post on SO which discusses the difference between max-age=0 and no-cache etc. . 在SO上有一篇很好的文章,讨论了max-age = 0和no-cache等之间的区别。

At the end all three might prevent caching your data but still have different meanings. 最后,这三个都可能阻止缓存数据,但含义仍然不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为我的asp.net mvc Web应用程序提供一个Repository类。 如何确保我正确处理所有东西 - Provide a Repository class for my asp.net mvc web application. How to make sure i am disposing eveything correctly 如何以编程方式在ASP.NET MVC中启动应用程序时禁用OutputCache - How to programmatically disable OutputCache on application start in ASP.NET MVC 实施OutputCache后,如何测试ASP.NET(使用MVC 3)应用程序? - How to test the ASP.NET (with MVC 3) application after implemented the OutputCache? Castle Windsor ASP.NET MVC 4和Web API相同的应用程序。 只有MVC控制器没有依赖关系? - Castle Windsor ASP.NET MVC 4 and Web API same application. Only if MVC controllers have no dependencies? 从ASP.Net Web API和MVC Web应用程序访问Microsoft Graph API(用于OneDrive)。 - Accessing Microsoft Graph API (for OneDrive) from ASP.Net Web API & MVC Web Application. 想在Asp.net Web应用程序上运行WPF应用程序。 - Want to run WPF application on Asp.net web application. 在ASP.NET MVC中使用身份验证的OutputCache困境 - OutputCache dilemma with authentication in ASP.NET MVC “/”应用程序中的 HTTP 404 服务器错误。 在 ASP.NET MVC 4 中 - HTTP 404 Server Error in '/' Application. in ASP.NET MVC 4 ASP.NET MVC Outputcache“线程安全” - ASP.NET MVC Outputcache “thread safe” 继承的ASP.NET MVC OutputCache无法正常工作 - ASP.NET MVC OutputCache inherited is not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM