ASP.NET OutPutCache VaryByParam and VaryByHeader with AJAX

你离开我真会死。 提交于 2019-12-05 18:32:34

问题


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.


回答1:


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




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/2786690/asp-net-outputcache-varybyparam-and-varybyheader-with-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!