0

As I know in ASP.NET Core we can store a session in memory, in sql server or in redis.

On that website: http://jiodev.com/aspnet/core/performance/caching/distributed I have found the article:

A distributed cache is shared by multiple app servers (see Caching Basics). >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.

As I understand I can use in memory distributed cache even if I have my application on multiple servers and I can share session? If yes then when to store session in sql server or redis?

1
  • When you actually get around to implementing it you should go with redis :) SQLServer is not a true memory cache. Commented Jun 13, 2019 at 19:16

1 Answer 1

2

An in-memory distributed cache is an oxymoron, unless you provide some way for the other servers in the cluster to connect to it and retrieve the cached data.

In your case, I think you could apply the simple rule:

  • 1 Server = In Memory
  • >1 Server = SQL Server or Redis (i.e. distributed).

If you re-read that article, I think you'll find that the two implementations of IDistributedCache talked about are SQL Server and Redis. There is no in-memory implementation of IDistributedCache and if there was, it would only be suitable for testing purposes.

Edit: As pointed out by ESG below, there is actually an in-memory implementation of IDistributedCache, but it is not actually a distributed cache, and as I stated above, is only useful for testing/development scenarios or where a distributed cache might be required in future.

Sign up to request clarification or add additional context in comments.

3 Comments

as per the doc: The Distributed Memory Cache isn't an actual distributed cache. Cached items are stored by the app instance on the server where the app is running.
so how we can share sessions among same app hosted on multiple servers in load balanced scenario?
In-memory caches can still be useful in production multi-server scenarios when you can ensure session-affinity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.