ZiggyCreatures / FusionCache

FusionCache is an easy to use, fast and robust hybrid cache with advanced resiliency features.
MIT License
1.65k stars 87 forks source link

Allow reuse of a Redis ConnectionMultiplexer instance between RedisCache and RedisBackplane #177

Closed JeffreyM closed 10 months ago

JeffreyM commented 11 months ago

Added a factory method (ConnectionMultiplexerFactory) to RedisBackplaneOptions similar to that found in Microsoft.Extensions.Caching.Redis.RedisCacheOptions. This will allow for the shared use of a ConnectionMultiplexer between a RedisCache and RedisBackplane.

var options = ConfigurationOptions.Parse("REDIS_CONNECTION_STRING");
var multiplexer = ConnectionMultiplexer.Connect(options);

var redisCache = new RedisCache(new RedisCacheOptions() { 
    ConnectionMultiplexerFactory = async () => await Task.FromResult((IConnectionMultiplexer)multiplexer).ConfigureAwait(false) });

var redisBackplane = new RedisBackplane(new RedisBackplaneOptions() { 
    ConnectionMultiplexerFactory = async () => await Task.FromResult((IConnectionMultiplexer)multiplexer).ConfigureAwait(false) });

builder.Services.AddFusionCache()
    .WithDistributedCache(redisCache)
    .WithBackplane(redisBackplane);
jodydonetti commented 11 months ago

Hi @JeffreyM and thanks for using FusionCache!

This is a good idea, and something I was thinking about for some time but never had time to sit down and do it. Right now I'm at the finish line of a very big new version, so I'll merge this soon and if needed will fix the potential conflicts that may emerge.

Will update you soon, thanks!

JeffreyM commented 11 months ago

Thank you @jodydonetti. Good luck with the next release and thank you for taking the time to create and maintain FusionCache. It's an extremely capable and approachable library and, bonus, has the best documentation of any FOSS project I've run across.

Hat tip to you!

jodydonetti commented 11 months ago

Thank you @jodydonetti. Good luck with the next release and thank you for taking the time to create and maintain FusionCache.

Thanks, I'm glad you're finding it useful!

It's an extremely capable and approachable library and, bonus, has the best documentation of any FOSS project I've run across.

Hat tip to you!

Wow, thanks for your words, they really mean a lot 😊