简体   繁体   中英

session in asp.net core in memory

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?

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 (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM