Reputation: 17677
I'm just reading about OutputCache
, and I see how you can apply VaryByParam
to change the cache based on parameters sent to the view, but I would like to change the cache based on both the parameters and the currently logged in user (using Asp.Nets default membership). I've been looking around, but I don't seem to be able to find a way to get this working.
Any suggestions on what I should try?
Upvotes: 1
Views: 177
Reputation: 42497
Use VaryByCustom. I implemented something like this:
[OutputCache(VaryByCustom="user")]
public ActionResult SomeAction()
{
return View();
}
and in Global.asax.cs
public override string GetVaryByCustomString(HttpContext context, string arg)
{
if (arg == "user")
{
return context.Request.User.Identity.IsAuthenticated ? context.Request.User.Identity.Name : string.Empty;
}
return base.GetVaryByCustomString(context, arg);
}
Upvotes: 4