C# 使用VaryByCustom使缓存无效
我想使用VaryByCustom属性使缓存无效。 以下代码用于缓存设置C# 使用VaryByCustom使缓存无效,c#,asp.net-mvc-4,caching,cache-invalidation,C#,Asp.net Mvc 4,Caching,Cache Invalidation,我想使用VaryByCustom属性使缓存无效。 以下代码用于缓存设置 public override string GetVaryByCustomString(HttpContext context, string arg) { if (!string.IsNullOrWhiteSpace(arg)) { if (context.User.Identity.Name != null) { return context.Us
public override string GetVaryByCustomString(HttpContext context, string arg)
{
if (!string.IsNullOrWhiteSpace(arg))
{
if (context.User.Identity.Name != null)
{
return context.User.Identity.Name;
}
}
return base.GetVaryByCustomString(context, arg);
}
您是这样使用它的: 确保使用以下属性装饰您的操作:
[OutputCache(Duration = 3600, VaryByParam = "*", Location = OutputCacheLocation.Server, VaryByCustom =
"YourStringThatIsArgParamInYourGlobalAsaxMethod")]
public ActionResult MyActionOnTheController(string myParam)
{
}
那么,你把代码放在哪里了,什么不起作用了?我把它放在了Global.asx中。我想根据该方法作为arg获取的VaryByCustom属性使缓存基无效。