Rig.TUnit.Caching.Hybrid 0.1.0-beta.2

This is a prerelease version of Rig.TUnit.Caching.Hybrid.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Rig.TUnit.Caching.Hybrid" Version="0.1.0-beta.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Rig.TUnit.Caching.Hybrid" Version="0.1.0-beta.2" />
                    
Directory.Packages.props
<PackageReference Include="Rig.TUnit.Caching.Hybrid" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Rig.TUnit.Caching.Hybrid --version 0.1.0-beta.2
                    
#r "nuget: Rig.TUnit.Caching.Hybrid, 0.1.0-beta.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Rig.TUnit.Caching.Hybrid@0.1.0-beta.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Rig.TUnit.Caching.Hybrid&version=0.1.0-beta.2&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Rig.TUnit.Caching.Hybrid&version=0.1.0-beta.2&prerelease
                    
Install as a Cake Tool

Rig.TUnit.Caching.Hybrid

Microsoft HybridCache provider — 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 plain IMemoryCache (use .Memory).

Prerequisites

  • .NET 10 SDK
  • Microsoft.Extensions.Caching.Hybrid 10.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.HybridCacheFixture
  • Rig.TUnit.Caching.Hybrid.Options.HybridCacheFixtureOptions
  • Rig.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.
  • GetOrCreateAsync warm hit: ~700 ns.
  • Stampede coalescing guarantees a single loader call per key within the coalescing window (~500 ms default).
  • Safe under full parallelism.

Troubleshooting

  • GetOrCreateAsync returns stale value after invalidation — check LocalCacheExpirationSeconds > 0 combined with the L2 clear; HybridCache does not broadcast invalidation events to the L1 unless an L2 is wired.
  • Value not invalidated by tag — confirm you tagged on insert: .WithTags(["orders"]) inside GetOrCreateAsync's options.

See docs/troubleshooting.md#hybrid.

Provider quirks + edge cases

  • HybridCache is a singleton in the DI container; pin it as AddSingleton if 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.Json by default; register custom if your values contain polymorphic types.

Benchmarks

See HybridCacheBenchmarks.cs; baseline in benchmarks/baseline-005.json.

License

MIT. See LICENSE.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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