1
1
#nullable enable
2
2
namespace Polly ;
3
3
4
- #pragma warning disable CA1062 // Validate arguments of public methods
5
4
public partial class Policy
6
5
{
7
6
/// <summary>
@@ -63,13 +62,22 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider
63
62
/// <returns>The policy instance.</returns>
64
63
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheProvider"/> is <see langword="null"/>.</exception>
65
64
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheKeyStrategy"/> is <see langword="null"/>.</exception>
66
- public static AsyncCachePolicy < TResult > CacheAsync < TResult > ( IAsyncCacheProvider cacheProvider , TimeSpan ttl , ICacheKeyStrategy cacheKeyStrategy , Action < Context , string , Exception > ? onCacheError = null )
65
+ public static AsyncCachePolicy < TResult > CacheAsync < TResult > (
66
+ IAsyncCacheProvider cacheProvider ,
67
+ TimeSpan ttl ,
68
+ ICacheKeyStrategy cacheKeyStrategy ,
69
+ Action < Context , string , Exception > ? onCacheError = null )
67
70
{
68
71
if ( cacheProvider == null )
69
72
{
70
73
throw new ArgumentNullException ( nameof ( cacheProvider ) ) ;
71
74
}
72
75
76
+ if ( cacheKeyStrategy is null )
77
+ {
78
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
79
+ }
80
+
73
81
return CacheAsync < TResult > ( cacheProvider . AsyncFor < TResult > ( ) , new RelativeTtl ( ttl ) , cacheKeyStrategy . GetCacheKey , onCacheError ) ;
74
82
}
75
83
@@ -88,13 +96,22 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider
88
96
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheProvider"/> is <see langword="null"/>.</exception>
89
97
/// <exception cref="ArgumentNullException">Thrown when <paramref name="ttlStrategy"/> is <see langword="null"/>.</exception>
90
98
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheKeyStrategy"/> is <see langword="null"/>.</exception>
91
- public static AsyncCachePolicy < TResult > CacheAsync < TResult > ( IAsyncCacheProvider cacheProvider , ITtlStrategy ttlStrategy , ICacheKeyStrategy cacheKeyStrategy , Action < Context , string , Exception > ? onCacheError = null )
99
+ public static AsyncCachePolicy < TResult > CacheAsync < TResult > (
100
+ IAsyncCacheProvider cacheProvider ,
101
+ ITtlStrategy ttlStrategy ,
102
+ ICacheKeyStrategy cacheKeyStrategy ,
103
+ Action < Context , string , Exception > ? onCacheError = null )
92
104
{
93
105
if ( cacheProvider == null )
94
106
{
95
107
throw new ArgumentNullException ( nameof ( cacheProvider ) ) ;
96
108
}
97
109
110
+ if ( cacheKeyStrategy is null )
111
+ {
112
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
113
+ }
114
+
98
115
return CacheAsync < TResult > ( cacheProvider . AsyncFor < TResult > ( ) , ttlStrategy , cacheKeyStrategy . GetCacheKey , onCacheError ) ;
99
116
}
100
117
@@ -256,6 +273,11 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(
256
273
throw new ArgumentNullException ( nameof ( cacheProvider ) ) ;
257
274
}
258
275
276
+ if ( cacheKeyStrategy is null )
277
+ {
278
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
279
+ }
280
+
259
281
return CacheAsync < TResult > ( cacheProvider . AsyncFor < TResult > ( ) , new RelativeTtl ( ttl ) , cacheKeyStrategy . GetCacheKey , onCacheGet , onCacheMiss , onCachePut , onCacheGetError , onCachePutError ) ;
260
282
}
261
283
@@ -296,6 +318,11 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(
296
318
throw new ArgumentNullException ( nameof ( cacheProvider ) ) ;
297
319
}
298
320
321
+ if ( cacheKeyStrategy is null )
322
+ {
323
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
324
+ }
325
+
299
326
return CacheAsync < TResult > ( cacheProvider . AsyncFor < TResult > ( ) , ttlStrategy , cacheKeyStrategy . GetCacheKey , onCacheGet , onCacheMiss , onCachePut , onCacheGetError , onCachePutError ) ;
300
327
}
301
328
@@ -439,8 +466,19 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
439
466
/// <returns>The policy instance.</returns>
440
467
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheProvider"/> is <see langword="null"/>.</exception>
441
468
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheKeyStrategy"/> is <see langword="null"/>.</exception>
442
- public static AsyncCachePolicy < TResult > CacheAsync < TResult > ( IAsyncCacheProvider < TResult > cacheProvider , TimeSpan ttl , ICacheKeyStrategy cacheKeyStrategy , Action < Context , string , Exception > ? onCacheError = null ) =>
443
- CacheAsync < TResult > ( cacheProvider , new RelativeTtl ( ttl ) , cacheKeyStrategy . GetCacheKey , onCacheError ) ;
469
+ public static AsyncCachePolicy < TResult > CacheAsync < TResult > (
470
+ IAsyncCacheProvider < TResult > cacheProvider ,
471
+ TimeSpan ttl ,
472
+ ICacheKeyStrategy cacheKeyStrategy ,
473
+ Action < Context , string , Exception > ? onCacheError = null )
474
+ {
475
+ if ( cacheKeyStrategy is null )
476
+ {
477
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
478
+ }
479
+
480
+ return CacheAsync < TResult > ( cacheProvider , new RelativeTtl ( ttl ) , cacheKeyStrategy . GetCacheKey , onCacheError ) ;
481
+ }
444
482
445
483
/// <summary>
446
484
/// <para>Builds an <see cref="AsyncPolicy{TResult}" /> that will function like a result cache for delegate executions returning a <typeparamref name="TResult"/>.</para>
@@ -457,11 +495,28 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
457
495
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheProvider"/> is <see langword="null"/>.</exception>
458
496
/// <exception cref="ArgumentNullException">Thrown when <paramref name="ttlStrategy"/> is <see langword="null"/>.</exception>
459
497
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheKeyStrategy"/> is <see langword="null"/>.</exception>
460
- public static AsyncCachePolicy < TResult > CacheAsync < TResult > ( IAsyncCacheProvider < TResult > cacheProvider , ITtlStrategy ttlStrategy , ICacheKeyStrategy cacheKeyStrategy , Action < Context , string , Exception > ? onCacheError = null )
498
+ public static AsyncCachePolicy < TResult > CacheAsync < TResult > (
499
+ IAsyncCacheProvider < TResult > cacheProvider ,
500
+ ITtlStrategy ttlStrategy ,
501
+ ICacheKeyStrategy cacheKeyStrategy ,
502
+ Action < Context , string , Exception > ? onCacheError = null )
461
503
{
504
+ if ( cacheKeyStrategy is null )
505
+ {
506
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
507
+ }
508
+
462
509
Action < Context , string > emptyDelegate = ( _ , _ ) => { } ;
463
510
464
- return CacheAsync < TResult > ( cacheProvider , ttlStrategy , cacheKeyStrategy . GetCacheKey , emptyDelegate , emptyDelegate , emptyDelegate , onCacheError , onCacheError ) ;
511
+ return CacheAsync < TResult > (
512
+ cacheProvider ,
513
+ ttlStrategy ,
514
+ cacheKeyStrategy . GetCacheKey ,
515
+ emptyDelegate ,
516
+ emptyDelegate ,
517
+ emptyDelegate ,
518
+ onCacheError ,
519
+ onCacheError ) ;
465
520
}
466
521
467
522
/// <summary>
@@ -479,11 +534,28 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(IAsyncCacheProvider<
479
534
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheProvider"/> is <see langword="null"/>.</exception>
480
535
/// <exception cref="ArgumentNullException">Thrown when <paramref name="ttlStrategy"/> is <see langword="null"/>.</exception>
481
536
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheKeyStrategy"/> is <see langword="null"/>.</exception>
482
- public static AsyncCachePolicy < TResult > CacheAsync < TResult > ( IAsyncCacheProvider < TResult > cacheProvider , ITtlStrategy < TResult > ttlStrategy , ICacheKeyStrategy cacheKeyStrategy , Action < Context , string , Exception > ? onCacheError = null )
537
+ public static AsyncCachePolicy < TResult > CacheAsync < TResult > (
538
+ IAsyncCacheProvider < TResult > cacheProvider ,
539
+ ITtlStrategy < TResult > ttlStrategy ,
540
+ ICacheKeyStrategy cacheKeyStrategy ,
541
+ Action < Context , string , Exception > ? onCacheError = null )
483
542
{
543
+ if ( cacheKeyStrategy is null )
544
+ {
545
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
546
+ }
547
+
484
548
Action < Context , string > emptyDelegate = ( _ , _ ) => { } ;
485
549
486
- return CacheAsync < TResult > ( cacheProvider , ttlStrategy , cacheKeyStrategy . GetCacheKey , emptyDelegate , emptyDelegate , emptyDelegate , onCacheError , onCacheError ) ;
550
+ return CacheAsync < TResult > (
551
+ cacheProvider ,
552
+ ttlStrategy ,
553
+ cacheKeyStrategy . GetCacheKey ,
554
+ emptyDelegate ,
555
+ emptyDelegate ,
556
+ emptyDelegate ,
557
+ onCacheError ,
558
+ onCacheError ) ;
487
559
}
488
560
489
561
/// <summary>
@@ -666,9 +738,23 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(
666
738
Action < Context , string > onCacheMiss ,
667
739
Action < Context , string > onCachePut ,
668
740
Action < Context , string , Exception > ? onCacheGetError ,
669
- Action < Context , string , Exception > ? onCachePutError ) =>
670
- CacheAsync < TResult > ( cacheProvider , new RelativeTtl ( ttl ) , cacheKeyStrategy . GetCacheKey , onCacheGet , onCacheMiss ,
671
- onCachePut , onCacheGetError , onCachePutError ) ;
741
+ Action < Context , string , Exception > ? onCachePutError )
742
+ {
743
+ if ( cacheKeyStrategy is null )
744
+ {
745
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
746
+ }
747
+
748
+ return CacheAsync < TResult > (
749
+ cacheProvider ,
750
+ new RelativeTtl ( ttl ) ,
751
+ cacheKeyStrategy . GetCacheKey ,
752
+ onCacheGet ,
753
+ onCacheMiss ,
754
+ onCachePut ,
755
+ onCacheGetError ,
756
+ onCachePutError ) ;
757
+ }
672
758
673
759
/// <summary>
674
760
/// <para>Builds an <see cref="AsyncPolicy{TResult}" /> that will function like a result cache for delegate executions returning a <typeparamref name="TResult"/>.</para>
@@ -700,8 +786,23 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(
700
786
Action < Context , string > onCacheMiss ,
701
787
Action < Context , string > onCachePut ,
702
788
Action < Context , string , Exception > ? onCacheGetError ,
703
- Action < Context , string , Exception > ? onCachePutError ) =>
704
- CacheAsync < TResult > ( cacheProvider , ttlStrategy . For < TResult > ( ) , cacheKeyStrategy . GetCacheKey , onCacheGet , onCacheMiss , onCachePut , onCacheGetError , onCachePutError ) ;
789
+ Action < Context , string , Exception > ? onCachePutError )
790
+ {
791
+ if ( cacheKeyStrategy is null )
792
+ {
793
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
794
+ }
795
+
796
+ return CacheAsync < TResult > (
797
+ cacheProvider ,
798
+ ttlStrategy . For < TResult > ( ) ,
799
+ cacheKeyStrategy . GetCacheKey ,
800
+ onCacheGet ,
801
+ onCacheMiss ,
802
+ onCachePut ,
803
+ onCacheGetError ,
804
+ onCachePutError ) ;
805
+ }
705
806
706
807
/// <summary>
707
808
/// <para>Builds an <see cref="AsyncPolicy{TResult}" /> that will function like a result cache for delegate executions returning a <typeparamref name="TResult"/>.</para>
@@ -733,8 +834,23 @@ public static AsyncCachePolicy<TResult> CacheAsync<TResult>(
733
834
Action < Context , string > onCacheMiss ,
734
835
Action < Context , string > onCachePut ,
735
836
Action < Context , string , Exception > ? onCacheGetError ,
736
- Action < Context , string , Exception > ? onCachePutError ) =>
737
- CacheAsync < TResult > ( cacheProvider , ttlStrategy , cacheKeyStrategy . GetCacheKey , onCacheGet , onCacheMiss , onCachePut , onCacheGetError , onCachePutError ) ;
837
+ Action < Context , string , Exception > ? onCachePutError )
838
+ {
839
+ if ( cacheKeyStrategy is null )
840
+ {
841
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
842
+ }
843
+
844
+ return CacheAsync < TResult > (
845
+ cacheProvider ,
846
+ ttlStrategy ,
847
+ cacheKeyStrategy . GetCacheKey ,
848
+ onCacheGet ,
849
+ onCacheMiss ,
850
+ onCachePut ,
851
+ onCacheGetError ,
852
+ onCachePutError ) ;
853
+ }
738
854
739
855
/// <summary>
740
856
/// <para>Builds an <see cref="AsyncPolicy{TResult}" /> that will function like a result cache for delegate executions returning a <typeparamref name="TResult"/>.</para>
0 commit comments