【发布时间】:2025-12-13 21:35:01
【问题描述】:
我想在控制器中缓存方法的结果。问题是我希望每小时在 :00 清除缓存。 duration="3600" 不是一个选项,因为例如,如果在 3:20 第一次调用该方法,缓存将持续到 4:20,我需要在 4:00 更新它,因为数据库将在此时更新,保持此数据最新非常重要。
我现在的 web.config 文件是这样的:
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="1HourCacheProfile" varyByParam="*" enabled="true" duration="3600" location="Server" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
并且我把这个注解放在我想要缓存的方法之前
[OutputCache(CacheProfile = "1HourCacheProfile")]
有谁知道如何做到这一点?
干杯
【问题讨论】:
-
你需要通过代码手动设置缓存头来做到这一点,配置工具帮不了你
标签: asp.net-mvc caching controller outputcache