You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET Core 7.0中CacheOutput()中间件的默认缓存时长是多少?

ASP.NET Core 7.0 中 CacheOutput/OutputCache 中间件的默认缓存时长

首先需要澄清:ASP.NET Core 7.0 官方自带的输出缓存能力对应的扩展方法是 OutputCache(),如果你是误写为 CacheOutput(),那么调用无参数的 .OutputCache() 时,默认缓存时长为 60 秒(1分钟)——这个值来自框架 OutputCacheOptions 的默认配置。

如果你的代码确实使用的是第三方库(比如 WebApi.OutputCache.V2)提供的 CacheOutput() 扩展方法,它的默认缓存时长通常是 10分钟(600秒),具体以对应库的默认设定为准。

针对你给出的代码:

app.MapGet("/cached", () => DateTime.Now.ToString()).CacheOutput();
  • 若基于官方输出缓存封装,默认缓存1分钟;
  • 若为第三方 WebApi.OutputCache 库,默认缓存10分钟。

你也可以通过显式参数覆盖默认时长,示例如下:

// 官方 OutputCache 设定5分钟缓存
app.MapGet("/cached", () => DateTime.Now.ToString()).OutputCache(policy => policy.Expire(TimeSpan.FromMinutes(5)));

// 第三方 WebApi.OutputCache 设定5分钟缓存
app.MapGet("/cached", () => DateTime.Now.ToString()).CacheOutput(300);

内容的提问来源于stack exchange,提问作者Ramil Aliyev 007

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 03:01:20