StackRedis.L1 icon indicating copy to clipboard operation
StackRedis.L1 copied to clipboard

Use L1 with ASP.NET Core distributed cache

Open martingust opened this issue 2 years ago • 2 comments

I cannot get StrackRedis.L1 to work with ASP.NET Core distributed cache.

It's configured as following:

services.AddStackExchangeRedisCache(options =>
                    {
                        options.Configuration = distributedCacheConfig.ConnectionString;
                        options.ConnectionMultiplexerFactory = async () =>
                        {
                            var mux = await ConnectionMultiplexer.ConnectAsync(options.Configuration);
                            _ = new StackRedis.L1.RedisL1Database(mux.GetDatabase());
                            return mux;
                        };
                    });

When running the application the RedisL1Database constructor gets called with no errors. However it does not seems like the in-memory cache layer is being used at all and Redis is instead being used as normal. Expecting the console to write mem cache hits. Also tired to set breakpoints inside L1 project with no hits.

I'm are running master of this project with Microsoft.Extensions.Caching.StackExchangeRedis/6.0.1 and StackExchange.Redis/2.2.4.

Should L1 work with ASP.NET Core distributed cache? Is there anything wrong in my configuration?

martingust avatar Sep 09 '22 14:09 martingust

Hi @martingust - I'm afraid support for the ConnectionMultiplexer isn't there. .NET is calling the GetDatabase() method itself - your RedisL1Database instance isn't used.

To support it we'd have to create an implementation of IConnectionMultiplexer where the GetDatabase() returns RedisL1Database instances.

johnnycardy avatar Sep 09 '22 15:09 johnnycardy

Hi @martingust - I'm afraid support for the ConnectionMultiplexer isn't there. .NET is calling the GetDatabase() method itself - your RedisL1Database instance isn't used.

To support it we'd have to create an implementation of IConnectionMultiplexer where the GetDatabase() returns RedisL1Database instances.

Hey @johnnycardy! Ok, thanks for your reply! We will look into how we can them working together.

martingust avatar Sep 12 '22 07:09 martingust