Asp.net mvc output cache, is it possible to cache a result that will be different for different users?

I read a few different things, it seems that the output cache does not cache a different copy of the results for each user. therefore, if user A has 3 menus, and user B has access to only 1 of them, will the caching of the view result display all 3?

How can I cache things for each user so that they don’t share?

thanks!

+4
source share
3 answers

Use VaryByCustom and override HttpApplication.GetVaryByCustomString:

public virtual string GetVaryByCustomString( HttpContext context, string custom ) { //Return a value unique per user //Change depending on the authentication of your site (fe make use of Session) return context.User.Identity.Name; } 

http://msdn.microsoft.com/en-us/library/system.web.httpapplication.getvarybycustomstring.aspx http://asp.net-tutorials.com/caching/more-output-cache/

+4
source

One solution is to pass a parameter with a number of menus. Then configure outputcache to cache for all parameters except this one.

You can also configure the cache output cache only on the client, and not on the server. This may be useful depending on your scenario.

+1
source

You can always cache user information in an asp.net session.

0
source

All Articles