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

余生颓废 提交于 2019-11-28 12:25:21

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.

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