3using System.Threading.Tasks;
24 public async Task<ResourceResult<byte[]>> GetBytesAsync(Uri uri,
ResourceFetchOptions options, CancellationToken ct =
default)
26 (
byte[]? Data,
string ContentType) = await this.cache.
TryGet(uri).ConfigureAwait(
false);
28 return new ResourceResult<byte[]>(Data, ResourceOrigin.Disk, ContentType);
37 await Services.Resilience.PolicyRunner.RunAsync(async cts =>
39 (
byte[]? Bytes,
string Type) = await this.cache.GetOrFetch(uri, options.ParentId, options.Permanent).ConfigureAwait(
false);
42 }, ct, Timeout, Retry).ConfigureAwait(
false);
44 return new ResourceResult<byte[]>(Data, ResourceOrigin.Network, ContentType);
50 IEnumerable<IAsyncPolicy>? policies,
51 CancellationToken ct =
default)
53 (
byte[]? Data,
string ContentType) = await this.cache.TryGet(uri).ConfigureAwait(
false);
55 return new ResourceResult<byte[]>(Data, ResourceOrigin.Disk, ContentType);
57 IEnumerable<IAsyncPolicy> ToApply;
65 ToApply =
new[] { Timeout, Retry };
72 await Services.Resilience.PolicyRunner.RunAsync(async cts =>
74 (
byte[]? Bytes,
string Type) = await this.cache.GetOrFetch(uri, options.ParentId, options.Permanent).ConfigureAwait(
false);
77 }, ct, ToApply is
IAsyncPolicy[] Arr ? Arr :
System.Linq.Enumerable.ToArray(ToApply)).ConfigureAwait(
false);
79 return new ResourceResult<byte[]>(Data, ResourceOrigin.Network, ContentType);
static readonly TimeSpan DownloadFile
Download file timeout
A set of never changing property constants and helpful values.
int? RetryAttempts
Optional per-call retry attempts override. If null, defaults are used.
TimeSpan? Timeout
Optional per-call timeout override. If null, defaults are used.
Default resource fetcher: retrieves content using Internet cache and applies resilience policies.
async Task< ResourceResult< byte[]> > GetBytesAsync(Uri uri, ResourceFetchOptions options, IEnumerable< IAsyncPolicy >? policies, CancellationToken ct=default)
Retrieves bytes for a URI with optional custom resilience policies. When policies is null,...
static TimeSpan DecorrelatedJitter(TimeSpan baseDelay, int attempt, TimeSpan? maxDelay=null)
Decorrelated jitter backoff ("full jitter") based on attempt number.
static bool IsTransient(Exception ex)
Heuristic transient error classification for network-bound work.
Base class that references services in the app.
Defines operations for caching arbitrary internet-fetchable content.
Task<(byte[]? Data, string ContentType)> TryGet(Uri Uri)
Tries to retrieve a cached blob for the specified URI.