Reputation: 2560
I would like to ask if System.Web.HttpContext.Current.Cache
is per User like the Sessions
or if it is per application. On which circumstances is nice to use Cache?.
Upvotes: 9
Views: 11150
Reputation: 223392
HttpContext.Cache Property - MSDN
There is one instance of the Cache class per application domain. As a result, the Cache object that is returned by the Cache property is the Cache object for all requests in the application domain.
For your question.
On which circumstances is nice to use Cache?.
Keep that information in Cache which will be shared by multiple users and (usually) if its readonly
. For example keeping lookup values in cache. You may see:
Caching Data in an ASP.NET Web Pages Site for Better Performance
Upvotes: 13
Reputation: 17614
There is only one cache object per key
value unlike session
which is individual to user.
As it is a collection so you can have multiple cache variables.
There are different flavor of caching available in asp.net.
Here is a msdn link
http://msdn.microsoft.com/en-us/library/ms178597%28v=vs.100%29.aspx
Upvotes: 2
Reputation: 45068
The cache is global in the context of the application. It doesn't matter who stores items or who accesses them - just that they know how to do so. It's useful for persisting data that can be identical per user, for instance.
Upvotes: 0
Reputation: 3272
It's per Application
and it's best to use when you have data that can be reused for multiple users/sessions.
For instance, a UserID will be stored in a Session
. A User's language or name may also be stored in the Session
.
But information useful to a group of Users or to all Users, has to be stored in the Cache
.
Have a look at this question too.
Upvotes: 2