Rig.TUnit.Caching.Hybrid
0.1.0-beta.2
dotnet add package Rig.TUnit.Caching.Hybrid --version 0.1.0-beta.2
NuGet\Install-Package Rig.TUnit.Caching.Hybrid -Version 0.1.0-beta.2
<PackageReference Include="Rig.TUnit.Caching.Hybrid" Version="0.1.0-beta.2" />
<PackageVersion Include="Rig.TUnit.Caching.Hybrid" Version="0.1.0-beta.2" />
<PackageReference Include="Rig.TUnit.Caching.Hybrid" />
paket add Rig.TUnit.Caching.Hybrid --version 0.1.0-beta.2
#r "nuget: Rig.TUnit.Caching.Hybrid, 0.1.0-beta.2"
#:package Rig.TUnit.Caching.Hybrid@0.1.0-beta.2
#addin nuget:?package=Rig.TUnit.Caching.Hybrid&version=0.1.0-beta.2&prerelease
#tool nuget:?package=Rig.TUnit.Caching.Hybrid&version=0.1.0-beta.2&prerelease
Rig.TUnit.Caching.Hybrid
Microsoft
HybridCacheprovider — L1 in-memory with stampede coalescing and tag invalidation. No container required.
What this package is
The Rig.TUnit adapter for Microsoft's
HybridCache.
HybridCacheFixture configures an HybridCache instance with sensible
test defaults (60 s default TTL, 1 MiB max payload, 1024-char max key,
local-cache TTL 30 s) and exposes the raw HybridCache plus a stampede
coalescing test surface. L2 distributed is off by default — pair with
Rig.TUnit.Caching.Redis if you want it.
When to use it
- Testing services using Microsoft's HybridCache.
- Verifying stampede coalescing for
GetOrCreateAsync. - Asserting tag-invalidation via
RemoveByTagAsync. - Not for: FusionCache (different semantics, use
.Fusion) or plainIMemoryCache(use.Memory).
Prerequisites
- .NET 10 SDK
Microsoft.Extensions.Caching.Hybrid10.x (transitive)
Quick start
using Rig.TUnit.Caching.Hybrid.Fixtures;
await using var fx = new HybridCacheFixture();
await fx.InitializeAsync();
var key = $"k-{Guid.NewGuid():N}";
var value = await fx.Cache.GetOrCreateAsync(key, async _ =>
{
await Task.Yield();
return "computed-value";
});
Options
| Property | Type | Default | Description |
|---|---|---|---|
DefaultExpirationSeconds |
int |
60 |
Distributed-tier TTL |
LocalCacheExpirationSeconds |
int |
30 |
L1 (in-memory) TTL |
MaximumPayloadBytes |
int |
1_048_576 |
1 MiB guard |
MaximumKeyLength |
int |
1024 |
Key length guard |
Section name: RigTUnit:HybridCache.
Fixture + helper APIs
Rig.TUnit.Caching.Hybrid.Fixtures.HybridCacheFixtureRig.TUnit.Caching.Hybrid.Options.HybridCacheFixtureOptionsRig.TUnit.Caching.Hybrid.Builder.HybridCacheRigBuilder
Per-test isolation
Per-fixture HybridCache instance. Each test owns its own cache; no
shared state unless you explicitly wire an L2 distributed tier.
Parallelism + performance
- Zero container startup.
GetOrCreateAsyncwarm hit: ~700 ns.- Stampede coalescing guarantees a single loader call per key within the coalescing window (~500 ms default).
- Safe under full parallelism.
Troubleshooting
GetOrCreateAsyncreturns stale value after invalidation — checkLocalCacheExpirationSeconds> 0 combined with the L2 clear;HybridCachedoes not broadcast invalidation events to the L1 unless an L2 is wired.- Value not invalidated by tag — confirm you tagged on insert:
.WithTags(["orders"])insideGetOrCreateAsync's options.
See docs/troubleshooting.md#hybrid.
Provider quirks + edge cases
HybridCacheis a singleton in the DI container; pin it asAddSingletonif you are composing your own service graph.- Tag invalidation is per-instance for L1 only; L2 tag invalidation requires a compatible backplane (not shipped here).
- Serializer is
System.Text.Jsonby default; register custom if your values contain polymorphic types.
Benchmarks
See HybridCacheBenchmarks.cs;
baseline in benchmarks/baseline-005.json.
Related docs
- Architecture diagram
- Glossary
- Family base:
Rig.TUnit.Caching - Sibling:
Rig.TUnit.Caching.Fusion
License
MIT. See LICENSE.
| 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
- Bogus (>= 35.6.1)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Caching.Hybrid (>= 9.8.0)
- Microsoft.Extensions.Caching.Memory (>= 10.0.0)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.0)
- Microsoft.Extensions.TimeProvider.Testing (>= 10.0.0)
- Rig.TUnit.Caching (>= 0.1.0-beta.2)
- TUnit.Core (>= 1.34.5)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Rig.TUnit.Caching.Hybrid:
| Package | Downloads |
|---|---|
|
Rig.TUnit.All
Meta-package containing every Rig.TUnit.* package. DISCOURAGED — prefer per-feature or per-stack meta-packages (Rig.TUnit, Rig.TUnit.Microservices). |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0-beta.2 | 56 | 4/27/2026 |
| 0.0.0-alpha.0.14 | 54 | 4/26/2026 |