@@ -97,17 +97,15 @@ public Task SetAsync(string key, DistributedCacheItem item, CancellationToken ca
9797/// <summary>
9898/// Distributed cache but all in memory (for testing)
9999/// </summary>
100- public sealed class DistributedMemoryCache : IDistributedCache , IDistributedLockFactory
100+ /// <remarks>
101+ /// Constructor
102+ /// </remarks>
103+ /// <param name="clock">Clock</param>
104+ public sealed class DistributedMemoryCache ( TimeProvider clock ) : IDistributedCache , IDistributedLockFactory
101105{
102- private readonly Microsoft . Extensions . Internal . ISystemClock clock ;
106+ private readonly TimeProvider clock = clock ;
103107
104- /// <summary>
105- /// Constructor
106- /// </summary>
107- /// <param name="clock">Clock</param>
108- public DistributedMemoryCache ( Microsoft . Extensions . Internal . ISystemClock clock ) => this . clock = clock ;
109-
110- internal sealed class FakeDistributedLock : IAsyncDisposable
108+ internal sealed class FakeDistributedLock : IAsyncDisposable
111109 {
112110 public ValueTask DisposeAsync ( )
113111 {
@@ -133,9 +131,9 @@ public Task DeleteAsync(string key, CancellationToken cancelToken = default)
133131 /// <inheritdoc />
134132 public Task < DistributedCacheItem > GetAsync ( string key , CancellationToken cancelToken = default )
135133 {
136- if ( items . TryGetValue ( key , out var item ) && item . Item1 > clock . UtcNow )
134+ if ( items . TryGetValue ( key , out var item ) && item . Item1 > clock . GetUtcNow ( ) )
137135 {
138- return Task . FromResult ( new DistributedCacheItem { Bytes = item . Item2 , Expiry = item . Item1 - clock . UtcNow } ) ;
136+ return Task . FromResult ( new DistributedCacheItem { Bytes = item . Item2 , Expiry = item . Item1 - clock . GetUtcNow ( ) } ) ;
139137 }
140138 return Task . FromResult < DistributedCacheItem > ( default ) ;
141139 }
@@ -145,7 +143,7 @@ public Task SetAsync(string key, DistributedCacheItem item, CancellationToken ca
145143 {
146144 if ( item . Bytes is not null )
147145 {
148- DateTimeOffset expire = clock . UtcNow + item . Expiry ?? throw new ArgumentException ( "Null expiry not allowed" ) ;
146+ DateTimeOffset expire = clock . GetUtcNow ( ) + item . Expiry ?? throw new ArgumentException ( "Null expiry not allowed" ) ;
149147 items [ key ] = new ( expire , item . Bytes ) ;
150148 }
151149 return Task . CompletedTask ;
@@ -306,20 +304,13 @@ private void RegisterChangeQueue()
306304 }
307305 }
308306
309- private class DistributedLock : IAsyncDisposable
307+ private class DistributedLock ( IConnectionMultiplexer connection , string lockKey , string lockToken ) : IAsyncDisposable
310308 {
311- private readonly IConnectionMultiplexer connection ;
312- private readonly string lockKey ;
313- private readonly string lockToken ;
314-
315- public DistributedLock ( IConnectionMultiplexer connection , string lockKey , string lockToken )
316- {
317- this . connection = connection ;
318- this . lockKey = lockKey ;
319- this . lockToken = lockToken ;
320- }
309+ private readonly IConnectionMultiplexer connection = connection ;
310+ private readonly string lockKey = lockKey ;
311+ private readonly string lockToken = lockToken ;
321312
322- public async ValueTask DisposeAsync ( )
313+ public async ValueTask DisposeAsync ( )
323314 {
324315 await connection . GetDatabase ( ) . LockReleaseAsync ( lockKey , lockToken ) ;
325316 }
0 commit comments