.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