I'm using VaryByCustom
to create an output cache on a per-browser and per-user basis:
[OutputCache(Duration = 6000, VaryByParam = "*", VaryByCustom="browser;userName")]
(I've overridden GetVaryByCustomString()
to make this work.)
I need to be able to remove a single user's output cache, without invalidating the output cache of different users, if possible. I've read about HttpResponse.RemoveOutputCacheItem()
, but that works by removing the output cache based on path. Is there any way to do this based on the VaryByCustom string?
You can take the advantage of
VaryByCustom
property in[OutputCache]
by overridingHttpApplication.GetVaryByCustomString
and checkHttpContext.Current.User.IsAuthenticated.
This is what I will create in Global.asax.cs file:
And then use it in OutputCache attribute:
but be careful that the username should be immutable in this case!
perhaps use
in an ActionFilter the you can build up the string including browser version and user
Why not have the user in the parameters and then it would be per-user through the VaryByParam.