ASP.NET OutPutCache VaryByParam 和 VaryByHeader 与 AJAX

发布于 2024-08-31 19:58:32 字数 546 浏览 4 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寄居人 2024-09-07 19:58:32

根据 此 MSDN 参考,VaryByParam 中的多个值应该用分号分隔,而不是逗号分隔。

According to this MSDN reference, multiple values in VaryByParam should be semicolon separated, not comma separated.

孤星 2024-09-07 19:58:32

尝试使用 www.fiddlertool.com 检查标头并查看它们是否首先被传递。

Try using www.fiddlertool.com to check the headers and see if they are being passed in the first place.

新雨望断虹 2024-09-07 19:58:32

您的持续时间设置为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文