@@ -12,11 +12,14 @@ namespace Metalama.Patterns.Caching.Backends.Redis;
12
12
/// instances of local caches.
13
13
/// </summary>
14
14
[ PublicAPI ]
15
- internal sealed class RedisCacheSynchronizer : CacheSynchronizer
15
+ internal sealed class RedisCacheSynchronizer (
16
+ CachingBackend underlyingBackend ,
17
+ RedisCacheSynchronizerConfiguration configuration )
18
+ : CacheSynchronizer ( underlyingBackend , configuration )
16
19
{
17
- private readonly bool _ownsConnection ;
18
- private readonly RedisChannel _channel ;
19
- private readonly TimeSpan _connectionTimeout ;
20
+ private readonly bool _ownsConnection = configuration . OwnsConnection ;
21
+ private readonly RedisChannel _channel = new ( configuration . ChannelName , RedisChannel . PatternMode . Literal ) ;
22
+ private readonly TimeSpan _connectionTimeout = configuration . ConnectionTimeout ;
20
23
21
24
private IConnectionMultiplexer ? _connection ;
22
25
@@ -27,27 +30,13 @@ internal sealed class RedisCacheSynchronizer : CacheSynchronizer
27
30
/// </summary>
28
31
private IConnectionMultiplexer Connection => this . _connection ?? throw new InvalidOperationException ( "The component is not initialized." ) ;
29
32
30
- public RedisCacheSynchronizer (
31
- CachingBackend underlyingBackend ,
32
- RedisCacheSynchronizerConfiguration configuration ) : base ( underlyingBackend , configuration )
33
- {
34
- this . _ownsConnection = configuration . OwnsConnection ;
35
- this . _connectionTimeout = configuration . ConnectionTimeout ;
36
- this . _channel = new RedisChannel ( configuration . ChannelName , RedisChannel . PatternMode . Literal ) ;
37
- }
38
-
39
33
protected override void InitializeCore ( )
40
34
{
41
35
var redisConnectionFactory = ( ( RedisCacheSynchronizerConfiguration ) this . Configuration ) . ConnectionFactory ;
42
36
43
- if ( redisConnectionFactory != null )
44
- {
45
- this . _connection = redisConnectionFactory . GetConnection ( this . ServiceProvider ) ;
46
- }
47
- else
48
- {
49
- this . _connection = this . ServiceProvider . GetRequiredService < IConnectionMultiplexer > ( ) ;
50
- }
37
+ this . _connection = redisConnectionFactory != null !
38
+ ? redisConnectionFactory . GetConnection ( this . ServiceProvider )
39
+ : this . ServiceProvider . GetRequiredService < IConnectionMultiplexer > ( ) ;
51
40
52
41
this . NotificationQueueProcessor = RedisNotificationQueueProcessor . Create (
53
42
this . ToString ( ) ,
@@ -64,7 +53,7 @@ protected override void InitializeCore()
64
53
{
65
54
var configuration = ( RedisCacheSynchronizerConfiguration ) this . Configuration ;
66
55
67
- if ( configuration . ConnectionFactory != null )
56
+ if ( configuration . ConnectionFactory != null ! )
68
57
{
69
58
this . _connection =
70
59
await configuration . ConnectionFactory . GetConnectionAsync (
0 commit comments