@@ -51,6 +51,18 @@ public OfflineSupportService(
5151 CachedRequest ? request = null ,
5252 TRes ? defaultResponse = default ,
5353 CancellationToken clt = default )
54+ {
55+ return await CachedRequestInternalAsync ( cacheKey , function , request , defaultResponse , retryOnFreshOffline : true , retryOnJsonException : true , clt ) ;
56+ }
57+
58+ private async Task < TRes ? > CachedRequestInternalAsync < [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicParameterlessConstructor ) ] TRes > (
59+ string cacheKey ,
60+ Func < Task < TRes > > function ,
61+ CachedRequest ? request = null ,
62+ TRes ? defaultResponse = default ,
63+ bool retryOnFreshOffline = true ,
64+ bool retryOnJsonException = true ,
65+ CancellationToken clt = default )
5466 {
5567 request ??= new CachedRequest ( ) ;
5668 try
@@ -93,7 +105,7 @@ public OfflineSupportService(
93105 {
94106 return await RunSaveAndReturn ( cacheKey , function , request , clt ) ;
95107 }
96-
108+
97109 var cacheResult = await _localStorageExpireService . GetItemAsync < TRes ? > ( cacheKey , clt ) ;
98110 if ( cacheResult is not null )
99111 {
@@ -114,11 +126,10 @@ public OfflineSupportService(
114126 ConsoleHelper . WriteLine ( "HttpRequestException" ) ;
115127 var oldOffline = IsOffline ;
116128 IsOffline = true ;
117- if ( ! oldOffline && request is { CacheWhenOffline : true , RetryOnFreshOffline : true } ) // Only retry once
129+ if ( ! oldOffline && retryOnFreshOffline && request is { CacheWhenOffline : true } ) // Only retry once
118130 {
119131 ConsoleHelper . WriteLine ( $ "Retry calling offline { cacheKey } ") ;
120- request . RetryOnFreshOffline = false ;
121- return await CachedRequestAsync ( cacheKey , function , request , defaultResponse , clt ) ;
132+ return await CachedRequestInternalAsync ( cacheKey , function , request , defaultResponse , retryOnFreshOffline : false , retryOnJsonException , clt ) ;
122133 }
123134 }
124135 catch ( TaskCanceledException )
@@ -129,11 +140,10 @@ public OfflineSupportService(
129140 // The object definition could be changed with an update. Deleting the old version and retrying again to get the latest version.
130141 ConsoleHelper . WriteLine ( $ "JsonException for { cacheKey } , Deleting") ;
131142 await _localStorageExpireService . DeleteItemAsync ( cacheKey , clt ) ;
132- if ( request . RetryOnJsonException ) // Only retry once
143+ if ( retryOnJsonException ) // Only retry once
133144 {
134145 ConsoleHelper . WriteLine ( $ "Retry calling { cacheKey } ") ;
135- request . RetryOnJsonException = false ;
136- return await CachedRequestAsync ( cacheKey , function , request , defaultResponse , clt ) ;
146+ return await CachedRequestInternalAsync ( cacheKey , function , request , defaultResponse , retryOnFreshOffline , false , clt ) ;
137147 }
138148
139149 ConsoleHelper . WriteLine ( $ "Will not retry { cacheKey } ") ;
0 commit comments