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>
@@ -70,6 +69,11 @@ public static CachePolicy<TResult> Cache<TResult>(ISyncCacheProvider cacheProvid
70
69
throw new ArgumentNullException ( nameof ( cacheProvider ) ) ;
71
70
}
72
71
72
+ if ( cacheKeyStrategy is null )
73
+ {
74
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
75
+ }
76
+
73
77
return Cache < TResult > ( cacheProvider . For < TResult > ( ) , new RelativeTtl ( ttl ) , cacheKeyStrategy . GetCacheKey , onCacheError ) ;
74
78
}
75
79
@@ -88,13 +92,22 @@ public static CachePolicy<TResult> Cache<TResult>(ISyncCacheProvider cacheProvid
88
92
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheProvider"/> is <see langword="null"/>.</exception>
89
93
/// <exception cref="ArgumentNullException">Thrown when <paramref name="ttlStrategy"/> is <see langword="null"/>.</exception>
90
94
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheKeyStrategy"/> is <see langword="null"/>.</exception>
91
- public static CachePolicy < TResult > Cache < TResult > ( ISyncCacheProvider cacheProvider , ITtlStrategy ttlStrategy , ICacheKeyStrategy cacheKeyStrategy , Action < Context , string , Exception > ? onCacheError = null )
95
+ public static CachePolicy < TResult > Cache < TResult > (
96
+ ISyncCacheProvider cacheProvider ,
97
+ ITtlStrategy ttlStrategy ,
98
+ ICacheKeyStrategy cacheKeyStrategy ,
99
+ Action < Context , string , Exception > ? onCacheError = null )
92
100
{
93
101
if ( cacheProvider == null )
94
102
{
95
103
throw new ArgumentNullException ( nameof ( cacheProvider ) ) ;
96
104
}
97
105
106
+ if ( cacheKeyStrategy is null )
107
+ {
108
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
109
+ }
110
+
98
111
return Cache < TResult > ( cacheProvider . For < TResult > ( ) , ttlStrategy , cacheKeyStrategy . GetCacheKey , onCacheError ) ;
99
112
}
100
113
@@ -256,6 +269,11 @@ public static CachePolicy<TResult> Cache<TResult>(
256
269
throw new ArgumentNullException ( nameof ( cacheProvider ) ) ;
257
270
}
258
271
272
+ if ( cacheKeyStrategy is null )
273
+ {
274
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
275
+ }
276
+
259
277
return Cache < TResult > ( cacheProvider . For < TResult > ( ) , new RelativeTtl ( ttl ) , cacheKeyStrategy . GetCacheKey , onCacheGet , onCacheMiss , onCachePut , onCacheGetError , onCachePutError ) ;
260
278
}
261
279
@@ -296,6 +314,11 @@ public static CachePolicy<TResult> Cache<TResult>(
296
314
throw new ArgumentNullException ( nameof ( cacheProvider ) ) ;
297
315
}
298
316
317
+ if ( cacheKeyStrategy is null )
318
+ {
319
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
320
+ }
321
+
299
322
return Cache < TResult > ( cacheProvider . For < TResult > ( ) , ttlStrategy , cacheKeyStrategy . GetCacheKey , onCacheGet , onCacheMiss , onCachePut , onCacheGetError , onCachePutError ) ;
300
323
}
301
324
@@ -439,8 +462,19 @@ public static CachePolicy<TResult> Cache<TResult>(ISyncCacheProvider<TResult> ca
439
462
/// <returns>The policy instance.</returns>
440
463
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheProvider"/> is <see langword="null"/>.</exception>
441
464
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheKeyStrategy"/> is <see langword="null"/>.</exception>
442
- public static CachePolicy < TResult > Cache < TResult > ( ISyncCacheProvider < TResult > cacheProvider , TimeSpan ttl , ICacheKeyStrategy cacheKeyStrategy , Action < Context , string , Exception > ? onCacheError = null ) =>
443
- Cache < TResult > ( cacheProvider , new RelativeTtl ( ttl ) , cacheKeyStrategy . GetCacheKey , onCacheError ) ;
465
+ public static CachePolicy < TResult > Cache < TResult > (
466
+ ISyncCacheProvider < TResult > cacheProvider ,
467
+ TimeSpan ttl ,
468
+ ICacheKeyStrategy cacheKeyStrategy ,
469
+ Action < Context , string , Exception > ? onCacheError = null )
470
+ {
471
+ if ( cacheKeyStrategy is null )
472
+ {
473
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
474
+ }
475
+
476
+ return Cache < TResult > ( cacheProvider , new RelativeTtl ( ttl ) , cacheKeyStrategy . GetCacheKey , onCacheError ) ;
477
+ }
444
478
445
479
/// <summary>
446
480
/// <para>Builds a <see cref="Policy{TResult}" /> that will function like a result cache for delegate executions returning a <typeparamref name="TResult"/>.</para>
@@ -457,12 +491,28 @@ public static CachePolicy<TResult> Cache<TResult>(ISyncCacheProvider<TResult> ca
457
491
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheProvider"/> is <see langword="null"/>.</exception>
458
492
/// <exception cref="ArgumentNullException">Thrown when <paramref name="ttlStrategy"/> is <see langword="null"/>.</exception>
459
493
/// <exception cref="ArgumentNullException">Thrown when <paramref name="cacheKeyStrategy"/> is <see langword="null"/>.</exception>
460
- public static CachePolicy < TResult > Cache < TResult > ( ISyncCacheProvider < TResult > cacheProvider , ITtlStrategy ttlStrategy , ICacheKeyStrategy cacheKeyStrategy , Action < Context , string , Exception > ? onCacheError = null )
494
+ public static CachePolicy < TResult > Cache < TResult > (
495
+ ISyncCacheProvider < TResult > cacheProvider ,
496
+ ITtlStrategy ttlStrategy ,
497
+ ICacheKeyStrategy cacheKeyStrategy ,
498
+ Action < Context , string , Exception > ? onCacheError = null )
461
499
{
500
+ if ( cacheKeyStrategy is null )
501
+ {
502
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
503
+ }
504
+
462
505
Action < Context , string > emptyDelegate = ( _ , _ ) => { } ;
463
506
464
- return Cache < TResult > ( cacheProvider , ttlStrategy . For < TResult > ( ) , cacheKeyStrategy . GetCacheKey ,
465
- emptyDelegate , emptyDelegate , emptyDelegate , onCacheError , onCacheError ) ;
507
+ return Cache < TResult > (
508
+ cacheProvider ,
509
+ ttlStrategy . For < TResult > ( ) ,
510
+ cacheKeyStrategy . GetCacheKey ,
511
+ emptyDelegate ,
512
+ emptyDelegate ,
513
+ emptyDelegate ,
514
+ onCacheError ,
515
+ onCacheError ) ;
466
516
}
467
517
468
518
/// <summary>
@@ -670,9 +720,23 @@ public static CachePolicy<TResult> Cache<TResult>(
670
720
Action < Context , string > onCacheMiss ,
671
721
Action < Context , string > onCachePut ,
672
722
Action < Context , string , Exception > ? onCacheGetError ,
673
- Action < Context , string , Exception > ? onCachePutError ) =>
674
- Cache < TResult > ( cacheProvider , new RelativeTtl ( ttl ) , cacheKeyStrategy . GetCacheKey , onCacheGet , onCacheMiss ,
675
- onCachePut , onCacheGetError , onCachePutError ) ;
723
+ Action < Context , string , Exception > ? onCachePutError )
724
+ {
725
+ if ( cacheKeyStrategy is null )
726
+ {
727
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
728
+ }
729
+
730
+ return Cache < TResult > (
731
+ cacheProvider ,
732
+ new RelativeTtl ( ttl ) ,
733
+ cacheKeyStrategy . GetCacheKey ,
734
+ onCacheGet ,
735
+ onCacheMiss ,
736
+ onCachePut ,
737
+ onCacheGetError ,
738
+ onCachePutError ) ;
739
+ }
676
740
677
741
/// <summary>
678
742
/// <para>Builds a <see cref="Policy{TResult}" /> that will function like a result cache for delegate executions returning a <typeparamref name="TResult"/>.</para>
@@ -704,8 +768,23 @@ public static CachePolicy<TResult> Cache<TResult>(
704
768
Action < Context , string > onCacheMiss ,
705
769
Action < Context , string > onCachePut ,
706
770
Action < Context , string , Exception > ? onCacheGetError ,
707
- Action < Context , string , Exception > ? onCachePutError ) =>
708
- Cache < TResult > ( cacheProvider , ttlStrategy , cacheKeyStrategy . GetCacheKey , onCacheGet , onCacheMiss , onCachePut , onCacheGetError , onCachePutError ) ;
771
+ Action < Context , string , Exception > ? onCachePutError )
772
+ {
773
+ if ( cacheKeyStrategy is null )
774
+ {
775
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
776
+ }
777
+
778
+ return Cache < TResult > (
779
+ cacheProvider ,
780
+ ttlStrategy ,
781
+ cacheKeyStrategy . GetCacheKey ,
782
+ onCacheGet ,
783
+ onCacheMiss ,
784
+ onCachePut ,
785
+ onCacheGetError ,
786
+ onCachePutError ) ;
787
+ }
709
788
710
789
/// <summary>
711
790
/// <para>Builds a <see cref="Policy{TResult}" /> that will function like a result cache for delegate executions returning a <typeparamref name="TResult"/>.</para>
@@ -737,8 +816,23 @@ public static CachePolicy<TResult> Cache<TResult>(
737
816
Action < Context , string > onCacheMiss ,
738
817
Action < Context , string > onCachePut ,
739
818
Action < Context , string , Exception > ? onCacheGetError ,
740
- Action < Context , string , Exception > ? onCachePutError ) =>
741
- Cache < TResult > ( cacheProvider , ttlStrategy , cacheKeyStrategy . GetCacheKey , onCacheGet , onCacheMiss , onCachePut , onCacheGetError , onCachePutError ) ;
819
+ Action < Context , string , Exception > ? onCachePutError )
820
+ {
821
+ if ( cacheKeyStrategy is null )
822
+ {
823
+ throw new ArgumentNullException ( nameof ( cacheKeyStrategy ) ) ;
824
+ }
825
+
826
+ return Cache < TResult > (
827
+ cacheProvider ,
828
+ ttlStrategy ,
829
+ cacheKeyStrategy . GetCacheKey ,
830
+ onCacheGet ,
831
+ onCacheMiss ,
832
+ onCachePut ,
833
+ onCacheGetError ,
834
+ onCachePutError ) ;
835
+ }
742
836
743
837
/// <summary>
744
838
/// <para>Builds a <see cref="Policy{TResult}" /> that will function like a result cache for delegate executions returning a <typeparamref name="TResult"/>.</para>
0 commit comments