簡體   English   中英

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

[英]Caching in ASP.NET 5 in Controller

我試圖像在ASP.NET MVC 5中那樣緩存輸出控制器。

我在ASP.NET MVC 5 Controller中做到了這一點:

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

現在,我在ASP.NET 5 MVC 6中嘗試這樣做:

控制器屬性:

[ResponseCache(CacheProfileName = "TestCache")]

在我的Startup.cs中

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

我在TestController中添加了一個斷點,但每次都會觸發breakboint。

我該如何解決?

您應該使用此處描述的MVC操作的新屬性。 例如

[ResponseCache(Duration=60)]

對應於

[OutputCache(Duration = 60)]

它放置HTTP標頭

Cache-Control: public,max-age=60

在相應的HTTP響應中。

如果您更喜歡使用緩存配置文件,您可以在同一篇文章中找到有關使用情況的相應信息(請參閱此處 )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM