@@ -106,10 +106,10 @@ public async ValueTask FlushAsync()
106
106
for ( int i = 0 , l = CacheLayers . Length ; i < l ; i ++ )
107
107
{
108
108
var layer = CacheLayers [ i ] ;
109
- await layer . FlushAsync ( ) ;
109
+ await layer . FlushAsync ( ) . ConfigureAwait ( false ) ;
110
110
}
111
111
112
- await Extensions . OnCacheFlushAsync ( ) ;
112
+ await Extensions . OnCacheFlushAsync ( ) . ConfigureAwait ( false ) ;
113
113
}
114
114
115
115
/// <inheritdoc/>
@@ -120,7 +120,7 @@ public async ValueTask CleanupAsync()
120
120
for ( int i = 0 , l = CacheLayers . Length ; i < l ; i ++ )
121
121
{
122
122
var layer = CacheLayers [ i ] ;
123
- await layer . CleanupAsync ( ) ;
123
+ await layer . CleanupAsync ( ) . ConfigureAwait ( false ) ;
124
124
}
125
125
}
126
126
@@ -137,10 +137,10 @@ public async ValueTask EvictAsync(string cacheKey)
137
137
for ( int i = 0 , l = CacheLayers . Length ; i < l ; i ++ )
138
138
{
139
139
var layer = CacheLayers [ i ] ;
140
- await layer . EvictAsync ( cacheKey ) ;
140
+ await layer . EvictAsync ( cacheKey ) . ConfigureAwait ( false ) ;
141
141
}
142
142
143
- await Extensions . OnCacheEvictionAsync ( cacheKey ) ;
143
+ await Extensions . OnCacheEvictionAsync ( cacheKey ) . ConfigureAwait ( false ) ;
144
144
}
145
145
146
146
/// <inheritdoc/>
@@ -154,7 +154,7 @@ public async ValueTask<CacheEntry<T>> SetAsync<T>(string cacheKey, T value, Time
154
154
}
155
155
156
156
var cacheEntry = new CacheEntry < T > ( value , timeToLive ) ;
157
- await InternalSetAsync ( cacheKey , cacheEntry , CacheUpdateType . AddOrUpdateEntry ) ;
157
+ await InternalSetAsync ( cacheKey , cacheEntry , CacheUpdateType . AddOrUpdateEntry ) . ConfigureAwait ( false ) ;
158
158
return cacheEntry ;
159
159
}
160
160
@@ -173,7 +173,7 @@ public async ValueTask SetAsync<T>(string cacheKey, CacheEntry<T> cacheEntry)
173
173
throw new ArgumentNullException ( nameof ( cacheEntry ) ) ;
174
174
}
175
175
176
- await InternalSetAsync ( cacheKey , cacheEntry , CacheUpdateType . AddOrUpdateEntry ) ;
176
+ await InternalSetAsync ( cacheKey , cacheEntry , CacheUpdateType . AddOrUpdateEntry ) . ConfigureAwait ( false ) ;
177
177
}
178
178
179
179
private async ValueTask InternalSetAsync < T > ( string cacheKey , CacheEntry < T > cacheEntry , CacheUpdateType cacheUpdateType )
@@ -184,15 +184,15 @@ private async ValueTask InternalSetAsync<T>(string cacheKey, CacheEntry<T> cache
184
184
185
185
try
186
186
{
187
- await layer . SetAsync ( cacheKey , cacheEntry ) ;
187
+ await layer . SetAsync ( cacheKey , cacheEntry ) . ConfigureAwait ( false ) ;
188
188
}
189
189
catch ( CacheSerializationException ex )
190
190
{
191
191
Logger . LogWarning ( ex , "Unable to set CacheKey={CacheKey} on CacheLayer={CacheLayer} due to an exception. This will result in cache misses on this layer." , cacheKey , layer . GetType ( ) ) ;
192
192
}
193
193
}
194
194
195
- await Extensions . OnCacheUpdateAsync ( cacheKey , cacheEntry . Expiry , cacheUpdateType ) ;
195
+ await Extensions . OnCacheUpdateAsync ( cacheKey , cacheEntry . Expiry , cacheUpdateType ) . ConfigureAwait ( false ) ;
196
196
}
197
197
198
198
/// <inheritdoc/>
@@ -208,11 +208,11 @@ private async ValueTask InternalSetAsync<T>(string cacheKey, CacheEntry<T> cache
208
208
for ( var layerIndex = 0 ; layerIndex < CacheLayers . Length ; layerIndex ++ )
209
209
{
210
210
var layer = CacheLayers [ layerIndex ] ;
211
- if ( await layer . IsAvailableAsync ( cacheKey ) )
211
+ if ( await layer . IsAvailableAsync ( cacheKey ) . ConfigureAwait ( false ) )
212
212
{
213
213
try
214
214
{
215
- var cacheEntry = await layer . GetAsync < T > ( cacheKey ) ;
215
+ var cacheEntry = await layer . GetAsync < T > ( cacheKey ) . ConfigureAwait ( false ) ;
216
216
if ( cacheEntry != default )
217
217
{
218
218
return cacheEntry ;
@@ -234,11 +234,11 @@ private async ValueTask InternalSetAsync<T>(string cacheKey, CacheEntry<T> cache
234
234
for ( var layerIndex = 0 ; layerIndex < CacheLayers . Length ; layerIndex ++ )
235
235
{
236
236
var layer = CacheLayers [ layerIndex ] ;
237
- if ( await layer . IsAvailableAsync ( cacheKey ) )
237
+ if ( await layer . IsAvailableAsync ( cacheKey ) . ConfigureAwait ( false ) )
238
238
{
239
239
try
240
240
{
241
- var cacheEntry = await layer . GetAsync < T > ( cacheKey ) ;
241
+ var cacheEntry = await layer . GetAsync < T > ( cacheKey ) . ConfigureAwait ( false ) ;
242
242
if ( cacheEntry != default )
243
243
{
244
244
return ( layerIndex , cacheEntry ) ;
@@ -270,7 +270,7 @@ public async ValueTask<T> GetOrSetAsync<T>(string cacheKey, Func<T, Task<T>> val
270
270
}
271
271
272
272
var currentTime = DateTimeProvider . Now ;
273
- var cacheEntryPoint = await GetWithLayerIndexAsync < T > ( cacheKey ) ;
273
+ var cacheEntryPoint = await GetWithLayerIndexAsync < T > ( cacheKey ) . ConfigureAwait ( false ) ;
274
274
var cacheEntryStatus = CacheEntryStatus . Stale ;
275
275
if ( cacheEntryPoint != default )
276
276
{
@@ -302,7 +302,7 @@ public async ValueTask<T> GetOrSetAsync<T>(string cacheKey, Func<T, Task<T>> val
302
302
cacheEntryStatus = CacheEntryStatus . Miss ;
303
303
}
304
304
305
- return ( await RefreshValueAsync ( cacheKey , valueFactory , settings , cacheEntryStatus ) ) ! . Value ! ;
305
+ return ( await RefreshValueAsync ( cacheKey , valueFactory , settings , cacheEntryStatus ) . ConfigureAwait ( false ) ) ! . Value ! ;
306
306
}
307
307
308
308
private async ValueTask BackPopulateCacheAsync < T > ( int fromIndexExclusive , string cacheKey , CacheEntry < T > cacheEntry )
@@ -314,9 +314,9 @@ private async ValueTask BackPopulateCacheAsync<T>(int fromIndexExclusive, string
314
314
for ( ; -- fromIndexExclusive >= 0 ; )
315
315
{
316
316
var previousLayer = CacheLayers [ fromIndexExclusive ] ;
317
- if ( await previousLayer . IsAvailableAsync ( cacheKey ) )
317
+ if ( await previousLayer . IsAvailableAsync ( cacheKey ) . ConfigureAwait ( false ) )
318
318
{
319
- await previousLayer . SetAsync ( cacheKey , cacheEntry ) ;
319
+ await previousLayer . SetAsync ( cacheKey , cacheEntry ) . ConfigureAwait ( false ) ;
320
320
}
321
321
}
322
322
}
@@ -333,7 +333,7 @@ private async ValueTask BackPopulateCacheAsync<T>(int fromIndexExclusive, string
333
333
{
334
334
try
335
335
{
336
- var previousEntry = await GetAsync < T > ( cacheKey ) ;
336
+ var previousEntry = await GetAsync < T > ( cacheKey ) . ConfigureAwait ( false ) ;
337
337
if ( previousEntry != default && entryStatus == CacheEntryStatus . Miss && previousEntry . Expiry >= DateTimeProvider . Now )
338
338
{
339
339
//The Cache Stack will always return an unexpired value if one exists.
@@ -344,26 +344,26 @@ private async ValueTask BackPopulateCacheAsync<T>(int fromIndexExclusive, string
344
344
return previousEntry ;
345
345
}
346
346
347
- await using var distributedLock = await Extensions . AwaitAccessAsync ( cacheKey ) ;
347
+ await using var distributedLock = await Extensions . AwaitAccessAsync ( cacheKey ) . ConfigureAwait ( false ) ;
348
348
349
349
CacheEntry < T > ? cacheEntry ;
350
350
if ( distributedLock . IsLockOwner )
351
351
{
352
352
var oldValue = previousEntry != default ? previousEntry . Value : default ;
353
- var refreshedValue = await asyncValueFactory ( oldValue ! ) ;
353
+ var refreshedValue = await asyncValueFactory ( oldValue ! ) . ConfigureAwait ( false ) ;
354
354
cacheEntry = new CacheEntry < T > ( refreshedValue , settings . TimeToLive ) ;
355
355
var cacheUpdateType = entryStatus switch
356
356
{
357
357
CacheEntryStatus . Miss => CacheUpdateType . AddEntry ,
358
358
_ => CacheUpdateType . AddOrUpdateEntry
359
359
} ;
360
- await InternalSetAsync ( cacheKey , cacheEntry , cacheUpdateType ) ;
360
+ await InternalSetAsync ( cacheKey , cacheEntry , cacheUpdateType ) . ConfigureAwait ( false ) ;
361
361
362
362
KeyLock . ReleaseLock ( cacheKey , cacheEntry ) ;
363
363
}
364
364
else
365
365
{
366
- cacheEntry = await GetAsync < T > ( cacheKey ) ;
366
+ cacheEntry = await GetAsync < T > ( cacheKey ) . ConfigureAwait ( false ) ;
367
367
}
368
368
369
369
return cacheEntry ;
@@ -377,15 +377,15 @@ private async ValueTask BackPopulateCacheAsync<T>(int fromIndexExclusive, string
377
377
else if ( entryStatus != CacheEntryStatus . Stale )
378
378
{
379
379
//Last minute check to confirm whether waiting is required
380
- var currentEntry = await GetAsync < T > ( cacheKey ) ;
380
+ var currentEntry = await GetAsync < T > ( cacheKey ) . ConfigureAwait ( false ) ;
381
381
if ( currentEntry != null && currentEntry . GetStaleDate ( settings ) > DateTimeProvider . Now )
382
382
{
383
383
KeyLock . ReleaseLock ( cacheKey , currentEntry ) ;
384
384
return currentEntry ;
385
385
}
386
386
387
387
//Lock until we are notified to be unlocked
388
- return await KeyLock . WaitAsync ( cacheKey ) as CacheEntry < T > ;
388
+ return await KeyLock . WaitAsync ( cacheKey ) . ConfigureAwait ( false ) as CacheEntry < T > ;
389
389
}
390
390
391
391
return default ;
@@ -410,11 +410,11 @@ public async ValueTask DisposeAsync()
410
410
}
411
411
else if ( layer is IAsyncDisposable asyncDisposableLayer )
412
412
{
413
- await asyncDisposableLayer . DisposeAsync ( ) ;
413
+ await asyncDisposableLayer . DisposeAsync ( ) . ConfigureAwait ( false ) ;
414
414
}
415
415
}
416
416
417
- await Extensions . DisposeAsync ( ) ;
417
+ await Extensions . DisposeAsync ( ) . ConfigureAwait ( false ) ;
418
418
419
419
Disposed = true ;
420
420
}
0 commit comments