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

前端 未结 2 1345
傲寒
傲寒 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.

    0 讨论(0)
  • 2020-12-11 07:31

    If you remove VaryByParam = "*" it should use your action method parameter values when caching.

    ASP.NET MVC 3’s output caching system no longer requires you to specify a VaryByParam property when declaring an [OutputCache] attribute on a Controller action method. MVC3 now automatically varies the output cached entries when you have explicit parameters on your action method – allowing you to cleanly enable output...

    Source: http://weblogs.asp.net/scottgu/archive/2010/12/10/announcing-asp-net-mvc-3-release-candidate-2.aspx

    [OutputCache(Duration = 100, VaryByHeader = "X-Requested-With")]
    public class CatalogController : BaseController
    {
        public ActionResult Index(string seller)
        {
            // I do something
        }
    }
    
    0 讨论(0)
提交回复
热议问题