Session in .NET Core 1.1

3k views Asked by At

I want to use Session in ASP.NET MVC CORE 1.1 but a bit confused.

What is the difference between:

services.AddDistributedMemoryCache(); vs services.AddMemoryCache();

It also looks like Session works without both of them, how come?

1

There are 1 answers

4
Sanket On BEST ANSWER

services.AddMemoryCache();

which represents a cache stored in the memory of the local web server.

services.AddDistributedMemoryCache();

which represents a cache shared by multiple app servers. The information in the cache is not stored in the memory of individual web servers, and the cached data is available to all of the app's servers. In this, you can configure both Redis and SQL Server distributed caches.

For more info, refer these links-

https://learn.microsoft.com/en-us/aspnet/core/performance/caching/memory https://learn.microsoft.com/en-us/aspnet/core/performance/caching/distributed