cash
cash

Reputation: 565

Does Redis Cache in .NET Core 3 requires the usage of the Stack Exchange package?

In .NET Core 2.2, in my Startup.cs, I had the following:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDistributedRedisCache(...);             
}

But now, in .NET Core 3.0, the AddDistributedRedisCache method can't be found. In docs, the "Applies to" section shows support only up to .NET Core 2.2

Following this tutorial from Microsoft, they use services.AddStackExchangeRedisCache in the example. Does it means that I'm required to install the Stack Exchange NuGet package for Redis? Why did the native Microsoft's Redis client solution removed?

Upvotes: 3

Views: 11947

Answers (2)

divinebovine
divinebovine

Reputation: 168

It took a bit of digging through their git repos, but it has been removed. The removal did not happen in the current repository, https://github.com/aspnet/Extensions, but in the previous repository, that is now archived, https://github.com/aspnet/Caching.

You can see some of the issues with the original package in this thread: https://github.com/aspnet/Caching/issues/410#issuecomment-418912525

The removal happened here: https://github.com/aspnet/Caching/issues/423

I've looked through the list of breaking changes in aspnet from 2.1 -> 2.2 and 2.2 -> 3.0 and nothing is listed for it. I'm going to create an issue on the documentation to see it included.

At this point, I believe the answer is to use the StackExchange version. It apparently has some major improvements over the older package anyway.

UPDATE: The latest package supported would be Microsoft.Extensions.Caching.StackExchangeRedis simply utilising this package would be best for .NET Core 3.0 and above.

Something along the lines of

services.AddStackExchangeRedisCache(action =>
                {
                    action.InstanceName = "WhatYouWantToNameIt";
                    action.Configuration = "127.0.0.1:6379";
                });

Documentation is here!

Upvotes: 15

Leisen Chang
Leisen Chang

Reputation: 876

To use AddDistributedRedisCache, you need to install Microsoft.Extensions.Caching.Redis from nuget. On the other hand, if you check the document you post carefully, AdddistributedRedisCache use RedisCacheOptions and the ConfigurationOptions property is StackExchange.Redis.ConfigurationOptions.

Upvotes: 1

Related Questions