我正在尝试缓存 HTTP 处理程序的 JSON 输出(不是 ASP.NET 页面,因此页面级 OutputCache 指令不适用)。我在 Windows Server 2008 上运行 IIS 7.5。
我在 Web.config 中添加了几行以在用户模式下启用缓存(不是内核模式,因为我需要身份验证):
<system.webServer>
<caching enabled="true" enableKernelCache="false">
<profiles>
<!-- cache content according to full query string for 12 hours -->
<add varyByQueryString="*" duration="12:00:00" policy="CacheForTimePeriod" extension=".aspx" />
</profiles>
</caching>
<urlCompression dynamicCompressionBeforeCache="true" />
</system.webServer>
<location path="Content">
<system.webServer>
<!-- cache content that's requested twice in 30 minutes -->
<serverRuntime enabled="true" frequentHitThreshold="2" frequentHitTimePeriod="00:30:00" />
</system.webServer>
</location>
内容确实成功缓存,但它只存在 60 seconds。我查看了各种配置文件(Web.config、applicationHost.config、机器配置)的某种 60 秒的 TTL,但我不知所措。
我怀疑缓存清除程序每次运行时都可能会吃掉我的缓存条目。我修改了注册表项,使清道夫的运行频率降低;那没有帮助。
我还怀疑 IIS 过度清除缓存是因为机器使用了大量的物理 RAM。此特定服务器的物理 RAM 饱和度约为 66%。我试图为输出缓存分配一个静态量(1 GB),而不是让 IIS 管理缓存,但这也没有成功。
我相信这与Stack Overflow 页面上提出的问题相同,但那个人从未得到答案。
提前致谢。
编辑:我终于能够通过修改 OutputCacheTTL 和 ObjectCacheTTL 注册表值来解决这个问题,如这篇非常有用的文章中所述。似乎微软文档相当不完整。