IIS7 输出缓存 - 仅在缓存中存在 60 秒?
我正在尝试缓存 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 秒。我查看了各种配置文件(Web.config、applicationHost.config、机器配置),寻找某种 60 秒的 TTL,但我不知所措。
我怀疑缓存清道夫可能会在每次运行时吃掉我的缓存条目。我修改了注册表项,以便减少清道夫运行的频率;但这没有帮助。
我还怀疑 IIS 过度清除缓存,因为机器正在使用大量物理 RAM。此特定服务器的物理 RAM 饱和度约为 66%。我尝试为输出缓存分配静态量(1 GB),而不是让 IIS 管理缓存,但这也没有成功。
我相信这与 对此提出的问题相同Stack Overflow 页面 但那家伙从未得到答案。
提前致谢。
编辑:我终于能够通过修改OutputCacheTTL和ObjectCacheTTL注册表值来解决这个问题,如这篇非常有用的文章。看来微软的文档相当不完整。
I'm trying to cache the JSON output of an HTTP Handler (NOT an ASP.NET page, so the Page-level OutputCache directive does not apply). I'm running IIS 7.5 on Windows Server 2008.
I've added lines to the Web.config to enable caching in user mode (not kernel mode, as I need authentication):
<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>
The content does successfully cache, but it lives only for 60 seconds. I have looked all over the various config files (Web.config, applicationHost.config, machine config) for a some sort of TTL of 60 seconds, but I'm at a loss.
I suspected that the cache scavenger might be eating my cache entries each time it runs. I modified the registry key so the scavenger runs less often; that did not help.
I also suspected that IIS was overagressively clearing out the cache because the machine is using a lot of its physical RAM. This particular server has about 66% physical RAM saturation. I attempted to allocate a static amount (1 GB) to the output cache, rather than allowing IIS to manage the cache, but that was also unsuccesful.
I believe this is the same question as asked on this Stack Overflow page but that guy never got an answer.
Thanks in advance.
EDIT: I was finally able to solve this problem by modifying the OutputCacheTTL and ObjectCacheTTL registry values, as described in this very helpful article. Seems the Microsoft documentation is rather incompletel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论