NoStore
属性用于通知代理服务器和浏览器,它们不应通过在请求头中设置Cache-Control: no-store
来存储缓存内容的永久副本.
Duration simply specifies how long the content of the controller action should be cached, e.g. 10seconds. This will set the Cache-Control: max-age
to >= 0. And also sets the Expires
header to a valid timestamp.
对于你最初的问题,不,这三种变体的含义不同.
[OutputCache(Duration = 0, Location = OutputCacheLocation.Client, VaryByParam = "*")]
创建这样的缓存头
Cache-Control: private, max-age=0
Expires: Fri, 03 Jan 2014 12:32:15 GMT
[OutputCache(NoStore = true, Duration = 0, Location="None", VaryByParam = "*")]
创建以下缓存标头:
Cache-Control: no-cache, no-store
Pragma: no-cache
Expires: -1
这基本上就是你想要看到的,如果你想通过各种方式阻止缓存.VaryByParam是可选的(至少在MVC5中是这样),默认值是"*",因此您可以简单地使用[OutputCache(NoStore = true, Location = OutputCacheLocation.None)]
.
[OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
甚至创建了一个公共缓存控件...
Cache-Control: public, no-store, max-age=0
Expires: Fri, 03 Jan 2014 12:36:38 GMT
在SO上有一个很好的帖子,讨论了max-age=0 and no-cache etc.和max-age=0 and no-cache etc.之间的区别.
最后,这三种方法可能会阻止缓存数据,但仍有不同的含义.