I can't understand which container should I use for storing cache:
HttpContext.Current.Session
or MemoryCache
?
What is difference between data stored in HttpContext.Current.Session
and MemoryCache
?
I can't understand which container should I use for storing cache:
HttpContext.Current.Session
or MemoryCache
?
What is difference between data stored in HttpContext.Current.Session
and MemoryCache
?
you could user HttpContext.Current.Session when you are storing data for a specific user
MemoryCache is when you are storing data for all users, the data are shared between all users
Your sole question is: difference between Session
and Cache
... well Session
is specific to account or user account (each user specific access is part of session) whereas Cache
is global to the application. You store only common data which would be used across the application irrespective of user session in cache
. Now again your cache store could be persistent (if you chose to store in DB or in distributed cache like Redis
or Azure memcache
/ non-persistent like ASP.NET HttpContext.Cache
object which stores the cache object in worker process w3wp
... thus in case worker process dies by means of recycling the application pool, you loose the cache object)
Moreover by means of session, if you want to access the session across all the web servers (in a load balanced environment) then you should consider using a Pooled Session