37

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 do I need Microsoft.Extensions.Caching.StackExchangeRedis?
What advantages it has over Microsoft.Extensions.Caching.Redis?

ytan11
  • 908
  • 8
  • 18
Ghassan Karwchan
  • 3,355
  • 7
  • 37
  • 65

1 Answers1

50

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.

godot
  • 3,422
  • 6
  • 25
  • 42
Tseng
  • 61,549
  • 15
  • 193
  • 205
  • 9
    It's SOO confusing, there is no mention in the official documentation about the recommendation of a package not developed by Microsoft https://learn.microsoft.com/en-us/aspnet/core/performance/caching/distributed?view=aspnetcore-3.1 – Küzdi Máté Mar 30 '20 at 12:47
  • 5
    I just switched from Microsoft.Extensions.Caching.Redis to Microsoft.Extensions.Caching.StackExchangeRedis with Azure Redis, and I am seeing response rates improving dramatically. 50ms redis lookups were common, now 2ms is common. Crazy. – Brian MacKay Mar 25 '22 at 17:28