2
2
{
3
3
using System ;
4
4
using System . Collections . Generic ;
5
+ using System . Threading ;
5
6
using System . Threading . Tasks ;
6
7
using EasyCaching . Core ;
7
8
using global ::CSRedis ;
@@ -14,32 +15,35 @@ public partial class DefaultCSRedisCachingProvider : EasyCachingAbstractProvider
14
15
/// </summary>
15
16
/// <returns>The async.</returns>
16
17
/// <param name="cacheKey">Cache key.</param>
17
- public override async Task < bool > BaseExistsAsync ( string cacheKey )
18
+ /// <param name="cancellationToken">CancellationToken</param>
19
+ public override async Task < bool > BaseExistsAsync ( string cacheKey , CancellationToken cancellationToken = default )
18
20
{
19
21
ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
20
22
21
23
return await _cache . ExistsAsync ( cacheKey ) ;
22
24
}
23
-
25
+
24
26
/// <summary>
25
27
/// Flushs the async.
26
28
/// </summary>
29
+ /// <param name="cancellationToken">CancellationToken</param>
27
30
/// <returns>The async.</returns>
28
- public override async Task BaseFlushAsync ( )
31
+ public override async Task BaseFlushAsync ( CancellationToken cancellationToken = default )
29
32
{
30
33
if ( _options . EnableLogging )
31
34
_logger ? . LogInformation ( "Redis -- FlushAsync" ) ;
32
35
33
36
await _cache . NodesServerManager . FlushDbAsync ( ) ;
34
37
}
35
-
38
+
36
39
/// <summary>
37
40
/// Gets all async.
38
41
/// </summary>
39
42
/// <returns>The all async.</returns>
40
43
/// <param name="cacheKeys">Cache keys.</param>
44
+ /// <param name="cancellationToken">CancellationToken</param>
41
45
/// <typeparam name="T">The 1st type parameter.</typeparam>
42
- public override async Task < IDictionary < string , CacheValue < T > > > BaseGetAllAsync < T > ( IEnumerable < string > cacheKeys )
46
+ public override async Task < IDictionary < string , CacheValue < T > > > BaseGetAllAsync < T > ( IEnumerable < string > cacheKeys , CancellationToken cancellationToken = default )
43
47
{
44
48
ArgumentCheck . NotNullAndCountGTZero ( cacheKeys , nameof ( cacheKeys ) ) ;
45
49
@@ -67,8 +71,9 @@ public override async Task<IDictionary<string, CacheValue<T>>> BaseGetAllAsync<T
67
71
/// <param name="cacheKey">Cache key.</param>
68
72
/// <param name="dataRetriever">Data retriever.</param>
69
73
/// <param name="expiration">Expiration.</param>
74
+ /// <param name="cancellationToken">CancellationToken</param>
70
75
/// <typeparam name="T">The 1st type parameter.</typeparam>
71
- public override async Task < CacheValue < T > > BaseGetAsync < T > ( string cacheKey , Func < Task < T > > dataRetriever , TimeSpan expiration )
76
+ public override async Task < CacheValue < T > > BaseGetAsync < T > ( string cacheKey , Func < Task < T > > dataRetriever , TimeSpan expiration , CancellationToken cancellationToken = default )
72
77
{
73
78
ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
74
79
ArgumentCheck . NotNegativeOrZero ( expiration , nameof ( expiration ) ) ;
@@ -120,7 +125,8 @@ public override async Task<CacheValue<T>> BaseGetAsync<T>(string cacheKey, Func<
120
125
/// <returns>The async.</returns>
121
126
/// <param name="cacheKey">Cache key.</param>
122
127
/// <param name="type">Object Type.</param>
123
- public override async Task < object > BaseGetAsync ( string cacheKey , Type type )
128
+ /// <param name="cancellationToken">CancellationToken</param>
129
+ public override async Task < object > BaseGetAsync ( string cacheKey , Type type , CancellationToken cancellationToken = default )
124
130
{
125
131
ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
126
132
@@ -151,8 +157,9 @@ public override async Task<object> BaseGetAsync(string cacheKey, Type type)
151
157
/// </summary>
152
158
/// <returns>The async.</returns>
153
159
/// <param name="cacheKey">Cache key.</param>
160
+ /// <param name="cancellationToken">CancellationToken</param>
154
161
/// <typeparam name="T">The 1st type parameter.</typeparam>
155
- public override async Task < CacheValue < T > > BaseGetAsync < T > ( string cacheKey )
162
+ public override async Task < CacheValue < T > > BaseGetAsync < T > ( string cacheKey , CancellationToken cancellationToken = default )
156
163
{
157
164
ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
158
165
@@ -183,7 +190,8 @@ public override async Task<CacheValue<T>> BaseGetAsync<T>(string cacheKey)
183
190
/// </summary>
184
191
/// <returns>The count.</returns>
185
192
/// <param name="prefix">Prefix.</param>
186
- public override Task < int > BaseGetCountAsync ( string prefix = "" )
193
+ /// <param name="cancellationToken">CancellationToken</param>
194
+ public override Task < int > BaseGetCountAsync ( string prefix = "" , CancellationToken cancellationToken = default )
187
195
{
188
196
if ( string . IsNullOrWhiteSpace ( prefix ) )
189
197
{
@@ -207,8 +215,9 @@ public override Task<int> BaseGetCountAsync(string prefix = "")
207
215
/// </summary>
208
216
/// <returns>The by prefix async.</returns>
209
217
/// <param name="prefix">Prefix.</param>
218
+ /// <param name="cancellationToken">CancellationToken</param>
210
219
/// <typeparam name="T">The 1st type parameter.</typeparam>
211
- public override async Task < IDictionary < string , CacheValue < T > > > BaseGetByPrefixAsync < T > ( string prefix )
220
+ public override async Task < IDictionary < string , CacheValue < T > > > BaseGetByPrefixAsync < T > ( string prefix , CancellationToken cancellationToken = default )
212
221
{
213
222
ArgumentCheck . NotNullOrWhiteSpace ( prefix , nameof ( prefix ) ) ;
214
223
@@ -229,13 +238,14 @@ public override async Task<IDictionary<string, CacheValue<T>>> BaseGetByPrefixAs
229
238
230
239
return result ;
231
240
}
232
-
241
+
233
242
/// <summary>
234
243
/// Removes all async.
235
244
/// </summary>
236
245
/// <returns>The all async.</returns>
237
246
/// <param name="cacheKeys">Cache keys.</param>
238
- public override async Task BaseRemoveAllAsync ( IEnumerable < string > cacheKeys )
247
+ /// <param name="cancellationToken">CancellationToken</param>
248
+ public override async Task BaseRemoveAllAsync ( IEnumerable < string > cacheKeys , CancellationToken cancellationToken = default )
239
249
{
240
250
ArgumentCheck . NotNullAndCountGTZero ( cacheKeys , nameof ( cacheKeys ) ) ;
241
251
@@ -254,19 +264,21 @@ public override async Task BaseRemoveAllAsync(IEnumerable<string> cacheKeys)
254
264
/// </summary>
255
265
/// <returns>The async.</returns>
256
266
/// <param name="cacheKey">Cache key.</param>
257
- public override async Task BaseRemoveAsync ( string cacheKey )
267
+ /// <param name="cancellationToken">CancellationToken</param>
268
+ public override async Task BaseRemoveAsync ( string cacheKey , CancellationToken cancellationToken = default )
258
269
{
259
270
ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
260
271
261
272
await _cache . DelAsync ( cacheKey ) ;
262
- }
273
+ }
263
274
264
275
/// <summary>
265
276
/// Removes the by prefix async.
266
277
/// </summary>
267
278
/// <returns>The by prefix async.</returns>
268
279
/// <param name="prefix">Prefix.</param>
269
- public override async Task BaseRemoveByPrefixAsync ( string prefix )
280
+ /// <param name="cancellationToken">CancellationToken</param>
281
+ public override async Task BaseRemoveByPrefixAsync ( string prefix , CancellationToken cancellationToken = default )
270
282
{
271
283
ArgumentCheck . NotNullOrWhiteSpace ( prefix , nameof ( prefix ) ) ;
272
284
@@ -293,8 +305,9 @@ public override async Task BaseRemoveByPrefixAsync(string prefix)
293
305
/// <returns>The all async.</returns>
294
306
/// <param name="value">Value.</param>
295
307
/// <param name="expiration">Expiration.</param>
308
+ /// <param name="cancellationToken">CancellationToken</param>
296
309
/// <typeparam name="T">The 1st type parameter.</typeparam>
297
- public override async Task BaseSetAllAsync < T > ( IDictionary < string , T > value , TimeSpan expiration )
310
+ public override async Task BaseSetAllAsync < T > ( IDictionary < string , T > value , TimeSpan expiration , CancellationToken cancellationToken = default )
298
311
{
299
312
//whether to use pipe based on redis mode
300
313
var tasks = new List < Task < bool > > ( ) ;
@@ -320,8 +333,9 @@ public override async Task BaseSetAllAsync<T>(IDictionary<string, T> value, Time
320
333
/// <param name="cacheKey">Cache key.</param>
321
334
/// <param name="cacheValue">Cache value.</param>
322
335
/// <param name="expiration">Expiration.</param>
336
+ /// <param name="cancellationToken">CancellationToken</param>
323
337
/// <typeparam name="T">The 1st type parameter.</typeparam>
324
- public override async Task BaseSetAsync < T > ( string cacheKey , T cacheValue , TimeSpan expiration )
338
+ public override async Task BaseSetAsync < T > ( string cacheKey , T cacheValue , TimeSpan expiration , CancellationToken cancellationToken = default )
325
339
{
326
340
ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
327
341
ArgumentCheck . NotNull ( cacheValue , nameof ( cacheValue ) , _options . CacheNulls ) ;
@@ -349,8 +363,9 @@ await _cache.SetAsync(
349
363
/// <param name="cacheKey">Cache key.</param>
350
364
/// <param name="cacheValue">Cache value.</param>
351
365
/// <param name="expiration">Expiration.</param>
366
+ /// <param name="cancellationToken">CancellationToken</param>
352
367
/// <typeparam name="T">The 1st type parameter.</typeparam>
353
- public override async Task < bool > BaseTrySetAsync < T > ( string cacheKey , T cacheValue , TimeSpan expiration )
368
+ public override async Task < bool > BaseTrySetAsync < T > ( string cacheKey , T cacheValue , TimeSpan expiration , CancellationToken cancellationToken = default )
354
369
{
355
370
ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
356
371
ArgumentCheck . NotNull ( cacheValue , nameof ( cacheValue ) , _options . CacheNulls ) ;
@@ -374,8 +389,9 @@ public override async Task<bool> BaseTrySetAsync<T>(string cacheKey, T cacheValu
374
389
/// Get the expiration of cache key async
375
390
/// </summary>
376
391
/// <param name="cacheKey">cache key</param>
392
+ /// <param name="cancellationToken">CancellationToken</param>
377
393
/// <returns>expiration</returns>
378
- public override async Task < TimeSpan > BaseGetExpirationAsync ( string cacheKey )
394
+ public override async Task < TimeSpan > BaseGetExpirationAsync ( string cacheKey , CancellationToken cancellationToken = default )
379
395
{
380
396
ArgumentCheck . NotNullOrWhiteSpace ( cacheKey , nameof ( cacheKey ) ) ;
381
397
0 commit comments