我正在尝试像在 ASP.NET MVC 5 中那样缓存输出 Controller 。
我在 ASP.NET MVC 5 Controller 中这样做:
[OutputCache(Duration = 60, VaryByParam = "*", Location = OutputCacheLocation.ServerAndClient)]
现在,我正在 ASP.NET 5 MVC 6 中尝试:
Controller 属性:
[ResponseCache(CacheProfileName = "TestCache")]
在我的Startup.cs中:
//Caching
services.Configure<MvcOptions>(options => options.CacheProfiles.Add("TestCache", new CacheProfile()
{
Duration = 3600,
Location = ResponseCacheLocation.Any,
VaryByHeader = "*"
}));
我在我的 TestController 中添加了一个断点,但每次都会触发断点。
我该如何解决?
最佳答案
您应该使用描述的 MVC 操作的新属性 here .例如
[ResponseCache(Duration=60)]
对应于
[OutputCache(Duration = 60)]
它放置 HTTP header
Cache-Control: public,max-age=60
在相应的 HTTP 响应中。
如果您更喜欢使用缓存配置文件,您将在同一篇文章中找到有关用法的相应信息(请参阅 here)。
关于asp.net - 在 Controller 中缓存 ASP.NET 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35129324/