Asp.net core Caching In-Memory and Distributed together

1.5k Views Asked by At

Can In-Memory caching and Distributed Cache be used together in the same application? Does it make sense after all?

A logic scenario that comes to my mind is to manager Session state (on top of In-Memory, taking advantage of sticky sessions ) and Distributed for other caching. However I don't know if this makes sense after all.

1

There are 1 best solutions below

4
On

Yes, you can. One implements IMemoryCache, other implements IDistributedCache.

IMemoryCache will not work properly if you have non-sticky sessions and multiple servers.

Also you may want to use service.AddDistributedMemoryCache(); instead of service.AddMemoryCache();