使用VaryByCustom使缓存失效

5
我希望使用VaryByCustom属性来使缓存失效。 以下代码用于设置缓存。
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);
}

那么你把这段代码放在哪里了,有什么问题? - Mathew Thompson
我把它放在Global.asx里了。我想根据此方法作为参数获取的VaryByCustom属性来使缓存失效。 - Shahzaib Hussain
基本上,我想要做到这一点https://dev59.com/t3fZa4cB1Zd3GeqPUKEb,但不使用MvcDonutCaching包。 - Shahzaib Hussain
1个回答

1

您是这样使用它的吗:

确保您在操作中使用属性进行装饰:

 [OutputCache(Duration = 3600, VaryByParam = "*", Location = OutputCacheLocation.Server, VaryByCustom = 
  "YourStringThatIsArgParamInYourGlobalAsaxMethod")]
  public ActionResult MyActionOnTheController(string myParam)
 {
 }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接