Skip to content

Commit 44af295

Browse files
committed
Those settings should not be exposed
1 parent 2923b7b commit 44af295

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

Src/Drogecode.Blazor.OfflineSupport/Models/CachedRequest.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,4 @@ public class CachedRequest
4141
/// Always return the cached response when offline, except when IgnoreCache is true.
4242
/// </summary>
4343
public bool CacheWhenOffline { get; set; } = true;
44-
45-
/// <summary>
46-
/// Retry once on JsonException.
47-
/// </summary>
48-
public bool RetryOnJsonException { get; set; } = true;
49-
50-
/// <summary>
51-
/// Retry when this is the call that triggers the offline state.
52-
/// </summary>
53-
public bool RetryOnFreshOffline { get; set; } = true;
5444
}

Src/Drogecode.Blazor.OfflineSupport/Services/OfflineSupportService.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)