The user session state is related to the web world, and the new MemoryCache is a new implementation that now generalizes caching availability for other types of applications, for example, a console application, winform applications, etc. MemoryCache is stored by the wrt domain of the application in which its instance was created, and is the application for all users accessing the application. Quote from this MSDN link:
The main differences between the Cache and MemoryCache classes are that the MemoryCache class has been modified to make it usable by .NET. Framework applications that are not ASP.NET applications. For example, the MemoryCache class has no dependencies on the System.Web assembly. Another difference is that you can create multiple instances of the MemoryCache Class for use in the same application and in the same AppDomain instance.
MemoryCache class is present in a separate assembly of System.Runtime.Caching.dll as a whole, which can be referenced
Note The MemoryCache class and System.Web.Caching.Cache are different implementations that lie in different dlls without interdependence. It's just that conceptually their behavior looks very similar to the fact that in any case they are a cache at the end of the day.
I would suggest reading this , this and this for a better understanding and some great ideas on this topic.
To answer your question:
- To save something that has a wide application but is lightweight , use Application Status .
- To save everything that is accessible , but resource - intensive - use Web Cache
- To save anything thatβs user-specific (usually light weight, as heavy-weight material will not scale along with the growing users of your site) - Use Session Status
While you are developing a website, an older web cache should be able to fulfill all your use cases. There may be very specialized use MemoryCache where you need the new MemoryCache , but I can't think about it right now.
source share