Does VaryByParam=“*” also read RouteData.Values?

前端 未结 2 1347
傲寒
傲寒 2020-12-11 06:53

in my asp.net mvc project, I enable output caching on a controller as below

[OutputCache(Duration = 100, VaryByParam = \"*\", VaryByHeader = \"X-Requested-Wi         


        
2条回答
  •  [愿得一人]
    2020-12-11 07:30

    The output caching mechanism varies by URL, QueryString, and Form. RouteData.Values is not represented here. The reason for this is that the output caching module runs before Routing, so when the second request comes in and the output caching module is looking for a matching cache entry, it doesn't even have a RouteData object to inspect.

    Normally this isn't a problem, as RouteData.Values comes straight from the URL, which is already accounted for. If you want to vary by some custom value, use VaryByCustom and GetVaryByCustomString to accomplish this.

提交回复
热议问题