ASP.NET OutPutCache VaryByParam 和 VaryByHeader 与 AJAX
我正在尝试使用 VaryByParam 和 VaryByHeader 进行一些缓存。当 AJAX 请求传入时,我返回部分 XHTML。当收到常规请求时,我会发送带有页眉/页脚的部分 XHTML 页面。
我尝试通过执行以下操作来缓存页面:
[OutputCache( Duration = 5, VaryByParam = "nickname,page", VaryByHeader = "X-Requested-With" )]
但是这不起作用...如果我先执行常规请求然后运行 AJAX 调用,我将获得完整的缓存页面而不是部分页面,反之亦然。似乎 VaryByHeader 被忽略了。是因为正常请求时省略了 X-Requested-With 吗?或者也许它正在执行 VaryByParam 或 VaryByHeader?
我明显的解决方法是让 AJAX 请求调用一个仅返回部分页面的不同方法,但是如果可能的话我想避免这种情况。
我将 ASP.NET MVC 1.0 与 OutputCacheAttribute 一起使用。
I'm trying to do some caching using VaryByParam AND VaryByHeader. When an AJAX request comes in I return a partial XHTML. When a regular request comes in I send the partial XHTML page with header / footer.
I tried to cache the page by doing:
[OutputCache( Duration = 5, VaryByParam = "nickname,page", VaryByHeader = "X-Requested-With" )]
However this doesn't work... if I do a regular request first then run the AJAX call I get the full cached page instead of the partial and vice-versa. Seems like VaryByHeader is being ignored. Is it because X-Requested-With is omitted on normal requests? Or perhaps it's doing VaryByParam OR VaryByHeader?
My obvious way around this is for AJAX requests to call a different method which only returns partial pages, however I'd like to avoid that if possible.
I'm using ASP.NET MVC 1.0 with the OutputCacheAttribute.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 此 MSDN 参考,VaryByParam 中的多个值应该用分号分隔,而不是逗号分隔。
According to this MSDN reference, multiple values in VaryByParam should be semicolon separated, not comma separated.
尝试使用 www.fiddlertool.com 检查标头并查看它们是否首先被传递。
Try using www.fiddlertool.com to check the headers and see if they are being passed in the first place.
您的持续时间设置为 5 秒。这是故意的吗?我怀疑这可能与您的缓存超时有关。
Your Duration is set to 5 seconds. Is this intentional? I suspect might have something to do with your cache timing out after this period.