I am a little bit lost. I am reading Microsoft documentation for ASP.NET Core caching using Redis. And the documentation suggests to use Microsoft.Extensions.Caching.StackExchangeRedis which is an open source third party library.
But I've seen some other tutorials are using Microsoft.Extensions.Caching.Redis, which is a more native asp.net core.
And at the end they both use the same interface IDistributedCache
Why I need StackExchangeRedis and what advantages it has over Microsoft.Extensions.Caching.Redis?
Redis is an open source in-memory data store, which is often used as a distributed cache. You can configure an Azure Redis Cache for an Azure-hosted ASP.NET Core app, and use an Azure Redis Cache for local development. An app configures the cache implementation using a RedisCache instance (AddStackExchangeRedisCache).
What is Redis Cache. Redis is an open source (BSD licensed), in-memory data structure store used as a database, cache, message broker, and streaming engine. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams.
You can download the complete Source Code here. Download free Redis Client to view the data from Redis. Let's start with creating a project in Visual Studio 2015. After creating a project, we are going to add a NuGet package to access Redis from an ASP.NET application.
It's a type of cloud cache service that provides Azure users with high throughput, low latency, and secure cache- fully managed by Microsoft. Azure Redis Cache is a distributed, in-memory cache service specifically designed for cloud applications.
A look at the dependency graph for Microsoft.Extensions.Caching.Redis and Microsoft.Extensions.Caching.StackExchangeRedis reveals it.
Microsoft.Extensions.Caching.Redis
is based on StackExchange redis 1.x library, whereas Microsoft.Extensions.Caching.StackExchangeRedis
is based on 2.x of the same library.
Also Microsoft.Extensions.Caching.Redis
doesn't seem to target the 3.1 extension libraries (Microsoft.Extensions.Options
/Caching.Abstractions
) where the other does.
So for .NET Core 3.x and newer use Microsoft.Extensions.Caching.StackExchangeRedis
as the previous one may not be maintained as long as the new one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With