问题描述
在我的asp.net mvc的项目,我在控制器上启用输出缓存如下
in my asp.net mvc project, I enable output caching on a controller as below
[OutputCache(Duration = 100, VaryByParam = "*", VaryByHeader = "X-Requested-With")]
public class CatalogController : BaseController
{
public ActionResult Index(string seller)
{
// I do something
}
}
它的伟大工程,直到创建自己的路线类,如下
it works great, until create my own Route class as below
public class MyRoute : Route
{
// there is a constructor here..
// I override this method..
// just to add one data called 'seller' to RouteData
public override RouteData GetRouteData(HttpContextBase httpContext)
{
var data = base.GetRouteData(httpContext);
if (data == null) return null;
var seller = DoSomeMagicHere();
// add seller
data.Values.Add("seller", seller);
return data;
}
}
然后,操作方法将卖家
作为参数。我总是通过提供不同的卖家
参数测试,但它需要从高速缓存的输出,而不是调用方法。
and then, the action method will take seller
as parameter. I tested it by always providing different seller
parameter, but it take the output from cache instead of calling the method.
确实设置的VaryByParam =*也被RouteData.Values各不相同,在asp.net mvc的?
does setting VaryByParam="*" also vary by RouteData.Values, in asp.net mvc?
我使用ASP.Net MVC 4 RC 3 2
I'm using ASP.Net 4 MVC 3 RC 2
推荐答案
输出缓存机制通过URL,查询字符串和形式各不相同。 RouteData.Values没有再在这里psented $ P $。这样做的原因是输出缓存模块路由之前运行,所以当第二个请求进来,输出缓存模块正在寻找一个匹配的高速缓存项,的它甚至没有一个的RouteData对象检查
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.
通常这不是一个问题,因为RouteData.Values从URL,它已经占到了来直。如果您想通过一些自定义值有所不同,使用VaryByCustom和GetVaryByCustomString做到这一点。
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.
这篇关于确实的VaryByParam =" * QUOT;也看过RouteData.Values?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!