如何配置 MVC 配置文件以不进行缓存

发布于 2024-12-11 01:52:45 字数 394 浏览 2 评论 0原文

我试图弄清楚如何将 ASP.NET MVC2 配置文件配置为完全没有缓存。我当前的配置文件有这个 xml 节点...

<caching>
  <outputCacheSettings>
    <outputCacheProfiles>
      <add name="ZeroCacheProfile" duration="0" varyByParam="*" location="None" />
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>

这向我表明,该应用程序没有进行缓存。我错过了什么吗?将继续浏览互联网寻找最简洁的答案。谢谢。

I am trying to figure out how to configure a ASP.NET MVC2 config file to have absolutely no caching. My current config file has this xml node...

<caching>
  <outputCacheSettings>
    <outputCacheProfiles>
      <add name="ZeroCacheProfile" duration="0" varyByParam="*" location="None" />
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>

That would indicate to me, that no caching is going on with with this application. Am I missing something? Will continue to browse the internet searching for the most succinct answer. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神回复 2024-12-18 01:52:45

除了定义缓存配置文件之外,在 web.config 中定义缓存配置文件本身不会做任何有用的事情。必须有一些东西使用这个缓存配置文件,否则它仍然是一个简单的定义。这就是工作的一半。

后半部分是装饰您想要使用 [OutputCache] 属性:

[OutputCache(CacheProfile = "ZeroCacheProfile")]

或者如果您想对站点的所有控制器执行此操作,请定义一个基本控制器,所有控制器都派生自该基本控制器,然后进行装饰这个基地具有上述属性的控制器。

Defining a cache profile in web.config per se doesn't do anything useful other than defining a cache profile. There must be something using this cache profile otherwise it stays a simple definition. So that's half of the job.

The second half is to decorate all your controllers or actions that you would like to disable caching for with the [OutputCache] attribute:

[OutputCache(CacheProfile = "ZeroCacheProfile")]

or if you want to do this for all controllers of your site define a base controller that all your controllers derive from and then decorate this base controller with the aforementioned attribute.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文