简体   繁体   English

在Controller 5中的ASP.NET 5中缓存

[英]Caching in ASP.NET 5 in Controller

I am trying to cache a output controller like I did in ASP.NET MVC 5. 我试图像在ASP.NET MVC 5中那样缓存输出控制器。

I did that in ASP.NET MVC 5 Controller: 我在ASP.NET MVC 5 Controller中做到了这一点:

 [OutputCache(Duration = 60, VaryByParam = "*", Location = OutputCacheLocation.ServerAndClient)]

Now, I'm trying that in ASP.NET 5 MVC 6: 现在,我在ASP.NET 5 MVC 6中尝试这样做:

Controller Attribute: 控制器属性:

[ResponseCache(CacheProfileName = "TestCache")]

In my Startup.cs : 在我的Startup.cs中

//Caching
            services.Configure<MvcOptions>(options => options.CacheProfiles.Add("TestCache", new CacheProfile()
            {
                Duration = 3600,
                Location = ResponseCacheLocation.Any,
                VaryByHeader = "*"
            }));

I have added a breakpoint in my TestController, but the breakboint is fired everytime. 我在TestController中添加了一个断点,但每次都会触发breakboint。

How can I fix it? 我该如何解决?

You should use new attributes of MVC Actions described here . 您应该使用此处描述的MVC操作的新属性。 For example 例如

[ResponseCache(Duration=60)]

corresponds to 对应于

[OutputCache(Duration = 60)]

It places HTTP header 它放置HTTP标头

Cache-Control: public,max-age=60

in the corresponding HTTP response. 在相应的HTTP响应中。

If you prefer to use caching profiles, you will find the corresponding information about the usage in the same article (see here ). 如果您更喜欢使用缓存配置文件,您可以在同一篇文章中找到有关使用情况的相应信息(请参阅此处 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM