Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalidate Cache using VaryByCustom

I want to invalidate cache using VaryByCustom attribute. Following code is being used for cache setup.

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);
}
like image 943
Shahzaib Hussain Avatar asked Nov 09 '22 10:11

Shahzaib Hussain


1 Answers

Are you using it like this:

Make sure you decorate your action with attribute:

 [OutputCache(Duration = 3600, VaryByParam = "*", Location = OutputCacheLocation.Server, VaryByCustom = 
  "YourStringThatIsArgParamInYourGlobalAsaxMethod")]
  public ActionResult MyActionOnTheController(string myParam)
 {
 }
like image 76
Vlado Pandžić Avatar answered Nov 15 '22 12:11

Vlado Pandžić