.net core響應緩存


按照官網資料操作無效,這里使用AspNetCore.ResponseCaching.Extensions的擴展包
安裝AspNetCore.ResponseCaching.Extensions
在Startup.cs添加配置

services.AddDiskBackedMemoryResponseCaching((x, y) =>
{
    //響應主體的最大可緩存大小(以字節為單位),默認64MB,對大多數情況而言可能太大了
    //Default of 64MB is probably way too big for most scenarios
    x.MaximumBodySize = 5 * 1024 * 1024;
});
//寫在app.UseMVC()之前
app.UseCustomResponseCaching();

在接口上添加ResponseCache特性(這部分內容看官網)

[ResponseCache(VaryByHeader = "User-Agent", Duration = 60,Location =ResponseCacheLocation.Any)]

示例代碼

Startup
ResponseCacheController

參考資料

AspNetCore.ResponseCaching.Extensions
ASP.Net Core 2.0 - ResponseCaching Middleware - Not Caching on Server
響應緩存在 ASP.NET Core


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM