本文介绍了的OutputCache我的asp.net MVC Web应用程序内设置。多个语法prevent缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个asp.net MVC的Web应用程序,我需要知道,如果有确定的OutputCache时,我的操作方法如下任何差异: -

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:-

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

VS

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

VS

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

将在上述的三个设置prevent缓存中的数据,或每个方面都有不同的意义?

Will all the above three setting prevent caching the data , or each on have different meaning ?

第二个问题是定义持续时间= 0 &放大器之间的主要区别; NoStore = TRUE ?将两者prevent缓存?
谢谢

Second question what is the main difference between defining duration=0 & NoStore=true ? will both of them prevent caching ?Thanks

推荐答案

NoStore 属性被用来通知代理服务器和浏览器,他们不应该存储的永久副本缓存的内容通过设置缓存控制:无店请求头中

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.

时间只需指定多久控制器操作的内容应该被缓存,例如持续10秒。这将设置的Cache-Control:max-age的来> = 0并且还设置了过期头到有效的时间戳。

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.

要您最初的问题,不,三个变化不具有相同的含义。

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

这基本上是要看到,如果你想通过各种手段prevent缓存内容。的VaryByParam是(至少在MVC5)可选,默认为*反正,所以你可以简单地使用 [的OutputCache(NoStore = TRUE,位置= OutputCacheLocation.None)] 来代替。

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.

[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

关于被如此好的帖子,其中讨论的max-age=0和无缓存等。

在结束所有三个威力prevent缓存的数据,但仍然有不同的含义。

At the end all three might prevent caching your data but still have different meanings.

这篇关于的OutputCache我的asp.net MVC Web应用程序内设置。多个语法prevent缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 07:21