[英]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=0
和NoStore=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.