不同的服务器和ASP.NET 4.0 中的客户端缓存策略
我对 ASP.NET 输出缓存缺乏一点基本的了解。
就我而言,我的资源与我的 VaryByCustom
键紧密相关。在服务器端,我希望这些可以无限期地缓存,直到该密钥发生变化。没有理由在计时器上清除这些缓存的条目。
然而,客户端应该每小时检查一次,以获得服务器认为是最新的内容。
如果我将持续时间设置为 1 小时,我就知道客户端上的过期标头设置正确。但它是否也会驱逐服务器端缓存?有没有办法确保响应在我的 VaryByCustom 更改之前一直缓存在服务器上,但仍然允许更频繁的客户端过期?
I'm missing a little fundamental understanding of ASP.NET Output Caching.
In my case I have resources that are very strongly tied to my VaryByCustom
key. On the server-side, I'd love for these to be cached indefinitely until that key changes. There's no reason for those cached entries to be purged on a timer.
Clients, however, should check in once an hour to get what the server considers to be the freshest content.
If I set my duration to 1 hour, I know that sets the expiration header on the client correctly. But does it also evict the server-side cache? Is there a way to ensure the response stays cached on the server until my VaryByCustom changes, but still allow a more frequent client-side expiration?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里需要注意的重要一点是,如果您的 VaryByCustom 发生更改,asp.net 会存储页面的单独缓存版本。
因此,假设您的 VaryByCustom-"custom1" 的 Duration="60" 那么这将被缓存 60 秒。
在此期间,如果您的 VaryByCustom 更改为“custom2”且持续时间=“60”,则 asp.net 将在缓存中存储一个单独的副本,该副本与“custom1”的缓存不同,并且此单独版本将缓存 60 秒。
测试这一点的一个简单方法是根据浏览器更改 VaryByCustom。
在 Global.asax
Aspx
页面加载
中,我没有在 aspx 中包含 asp:Label 的标记,但我希望您能了解总体思路。
The important thing to note here is that if your VaryByCustom changes, asp.net stores a separate cached version of the page.
So, supposing your VaryByCustom-"custom1" with Duration="60" then this will be cached for 60 seconds.
In between if your VaryByCustom changes to "custom2" with duration="60" asp.net will store a separate copy in the cache, which is different from the cache of "custom1" and this separate version will be cached for 60 seconds.
An easy way to test this is by changing VaryByCustom based on browser.
In Global.asax
Aspx
Page load
I havent included the markup for asp:Label in the aspx, but I hope you get the general idea.