asp.net-mvc - 什么是缓存配置文件?

标签 asp.net-mvc caching

我在看书的时候遇到了this article来自 MSDN 文档。我是缓存方面的新手,事实上,这是我阅读的有关缓存的第一篇文章。能简单解释一下吗?

最佳答案

简而言之,它是一个缓存配置文件,您可以在 web.config 中设置它,而不必将设置应用到您想要使用缓存设置的每个操作或 Controller :

在 web.config 中,您可以为缓存配置文件指定选项:

  <system.web>
    <compilation debug="true" targetFramework="4.5.1" />
    <httpRuntime targetFramework="4.5.1" />
    <caching>
      <outputCacheSettings>
        <outputCacheProfiles>
          <add name="cp1" duration="30" location="Any" varyByHeader="user-agent" />
        </outputCacheProfiles>
      </outputCacheSettings>
    </caching>
  </system.web>

然后你想在任何地方使用你可以使用的配置文件,例如

[OutputCache(CacheProfile="cp1")]
public ActionResult Index() {
     //...
}

以上示例取自 Apress Pro ASP.NET MVC 5 Platform by Adam Freeman . 我推荐它作为一本好书。

关于asp.net-mvc - 什么是缓存配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39668215/

相关文章:

asp.net - 如何找到对应值的枚举名称并在 DisplayFor 中使用它?

c# - 使用 'inherits' 关键字时不允许使用 'model' 关键字

asp.net-mvc - ASP.NET MVC : Unit testing controllers that use UrlHelper

c# - ajax.actionlink 调用 Controller Action

apache - 针对浏览器缓存的特定文件/文件夹

asp.net-mvc - ASP.NET MVC缓存如何处理AJAX请求?

android - 在 WebView 中缓存渐进式 Web 应用程序