Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the ASP.Net Cache shared between different user sessions?

In a page if I do the following:

Cache["key"] = myObject;

Is that cached object available for requests that are for other users?

like image 301
tpower Avatar asked Mar 04 '09 15:03

tpower


People also ask

Is cache user specific?

The ASP.Net Cache is attached to the application domain, so it's shared for all users. If you want to cache something for an individual user, use the Session object. ASP . Net Cache is supposed to be used for things which require extensive server resources but they are shared across users.

Is MemoryCache per user?

The ASP.NET Session object is per user key/value storage, whereas MemoryCache is an application level key/value storage (values are shared among all users).

Where does ASP.NET store cached data?

Cache is stored in web server memory.

How does ASP.NET handle cache?

To manually cache application data, you can use the MemoryCache class in ASP.NET. ASP.NET also supports output caching, which stores the generated output of pages, controls, and HTTP responses in memory. You can configure output caching declaratively in an ASP.NET Web page or by using settings in the Web.


1 Answers

Yes. The cache is Application level, and all users are in the same application.

If you need a per-user Cache you could use the Session, but that's not quite the same. The cache allows the framework to automatically expire items in a different way from the session. If you want the cache behavior on a per-user basis (not necessarily a good idea) you could build the user's ID into part of your key for the main cache.

like image 189
Joel Coehoorn Avatar answered Sep 30 '22 18:09

Joel Coehoorn