Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET: Cache per user

Using ASP.NET I am putting data into cache which is user-specific. The Site uses Windows-Authentication:

HttpContext.Current.Cache.Insert(....)

Is this cache available to the user only, or will any user who requests the cache with the same key get the same data?

like image 565
Ian Vink Avatar asked Feb 20 '26 02:02

Ian Vink


1 Answers

You can make the user name part of the key, e.g. "Joe.CacheKey1". It will be up to you to parse the key.

Some reasons why you might use Cache instead of Session:

  1. Session was disabled.
  2. Session's expiration policies don't meet your needs but Cache does
  3. You need to take advantage of some feature of cache that Session doesn't have, such as taking an action on item eviction, automatic eviction when there is memory pressure etc.

A bad reason to use Cache instead of Session is because you weren't aware that Session exists.

like image 103
MatthewMartin Avatar answered Feb 24 '26 06:02

MatthewMartin