Anarchy.Toolkit.Runtime.Workers.Caching
1.1.0
See the version list below for details.
dotnet add package Anarchy.Toolkit.Runtime.Workers.Caching --version 1.1.0
NuGet\Install-Package Anarchy.Toolkit.Runtime.Workers.Caching -Version 1.1.0
<PackageReference Include="Anarchy.Toolkit.Runtime.Workers.Caching" Version="1.1.0" />
<PackageVersion Include="Anarchy.Toolkit.Runtime.Workers.Caching" Version="1.1.0" />
<PackageReference Include="Anarchy.Toolkit.Runtime.Workers.Caching" />
paket add Anarchy.Toolkit.Runtime.Workers.Caching --version 1.1.0
#r "nuget: Anarchy.Toolkit.Runtime.Workers.Caching, 1.1.0"
#:package Anarchy.Toolkit.Runtime.Workers.Caching@1.1.0
#addin nuget:?package=Anarchy.Toolkit.Runtime.Workers.Caching&version=1.1.0
#tool nuget:?package=Anarchy.Toolkit.Runtime.Workers.Caching&version=1.1.0
Anarchy.Toolkit.Runtime.Workers.Caching
Part of Anarchy I/O Toolkit, a .NET developer platform · Pillar: Infrastructure · Layer: Runtime · Package catalog
The snapshot refresher: a worker that keeps the typed snapshots of Anarchy.Toolkit.Infrastructure.Caching up to date.
dotnet add package Anarchy.Toolkit.Runtime.Workers.Caching
When to use it
Use it in the job or worker that writes the snapshots readers take from ISnapshotCache<T> (for example a carrier
list read by several APIs from Redis). Each snapshot gets a loader that reads its source of truth; one worker calls the
loaders on an interval and stores their values. Readers only need Infrastructure.Caching and the shared store's
package.
How to use it
public sealed class CarrierListLoader(ICarrierRepository carriers) : ISnapshotLoader<CarrierList>
{
public async Task<CarrierList> LoadAsync(CancellationToken? cancellationToken = null) =>
new(await carriers.ListAsync(cancellationToken));
}
services
.UseModule(new ModuleRedisCache(c => c.GetRequired<RedisCacheOptions>("Redis")), configuration, environment)
.AddSnapshotCache(new SnapshotCacheOptions<CarrierList> { MaxAge = TimeSpan.FromMinutes(30) })
.AddSnapshotLoader<CarrierList, CarrierListLoader>(c => new SnapshotLoaderOptions {
Interval = TimeSpan.FromMinutes(10),
Timeout = TimeSpan.FromSeconds(30)
});
AddSnapshotLoader<T, TLoader>(configure) registers, with TryAdd:
TLoaderas the scopedISnapshotLoader<T>, resolved from a new scope for every load;- the snapshot cache of
Tand its freshness check as anIHealthCheck(AddSnapshotFreshnessHealthCheck<T>); - the refresher worker, once for every loader. Call
AddSnapshotRefresher(configure)first to set its options.
SnapshotLoaderOptions |
Default | Effect |
|---|---|---|
Interval |
5 minutes | Time between two loads of this snapshot |
Timeout |
1 minute | A load still running after it is abandoned (even when the loader ignores its token) and counted as failed |
SnapshotRefresherOptions |
Default | Effect |
|---|---|---|
PollInterval |
1 second | How often the worker checks which snapshots are due |
PreloadOnStart |
true |
Loads every snapshot while the host starts, before the worker reports started |
Worker |
ResilientWorkerOptions defaults |
Retry and failure policy of the worker loop itself |
Behaviour
- Parallel. The due snapshots load at the same time, each with its own timeout, so a slow source does not delay the others.
- Last good snapshot. A failed or timed-out load stores nothing: readers keep the previous snapshot, and the loop
goes on. The freshness check reports a snapshot once it is older than its
MaxAge. - Readiness. The freshness check fails until the first load succeeds. With
PreloadOnStartthat load happens before the host finishes starting; a failed preload does not stop the host. - Telemetry. Each load records
snapshot_refresher.load.execution_timeandsnapshot_refresher.load.execution_countthroughAppTelemetry, taggedsnapshot(the type name),outcome(success,failureortimeout) andsuccess; failures and timeouts are logged with the exception.
See the Infrastructure.Caching README and the toolkit overview.
Releases
See the release notes for the complete release history.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Anarchy.Toolkit.Core.Telemetry (>= 2.2.0)
- Anarchy.Toolkit.Infrastructure.Caching (>= 1.1.0)
- Anarchy.Toolkit.Runtime.Workers (>= 3.1.0)
- Humanizer (>= 3.0.10)
- Microsoft.Extensions.Caching.Hybrid (>= 10.11.1)
- Microsoft.Extensions.Caching.Memory (>= 10.0.15)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Configuration.Json (>= 10.0.15)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Diagnostics (>= 10.0.15)
- Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Hosting (>= 10.0.15)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Hosting.Systemd (>= 10.0.15)
- Microsoft.Extensions.Logging (>= 10.0.15)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.15)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.15)
- Newtonsoft.Json (>= 13.0.4)
- Polly.Core (>= 8.9.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
## Releases
### 1.1.0
- Follows `Bootstrap` 2.2.0 (`ModuleLibBootstrap`).
### 1.0.0
- Add `ISnapshotLoader<T>`, `SnapshotLoaderOptions`, `SnapshotRefresherOptions`, `AddSnapshotLoader<T, TLoader>` and `AddSnapshotRefresher`: one worker loads every registered snapshot on its interval, in parallel and each with its own timeout, preloads on start and keeps the last good snapshot on failure.