我在看书的时候遇到了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/