StackExchange.Redis.HybridCache 0.1.36-alpha

Prefix Reserved
This is a prerelease version of StackExchange.Redis.HybridCache.
dotnet add package StackExchange.Redis.HybridCache --version 0.1.36-alpha
                    
NuGet\Install-Package StackExchange.Redis.HybridCache -Version 0.1.36-alpha
                    
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="StackExchange.Redis.HybridCache" Version="0.1.36-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StackExchange.Redis.HybridCache" Version="0.1.36-alpha" />
                    
Directory.Packages.props
<PackageReference Include="StackExchange.Redis.HybridCache" />
                    
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 StackExchange.Redis.HybridCache --version 0.1.36-alpha
                    
#r "nuget: StackExchange.Redis.HybridCache, 0.1.36-alpha"
                    
#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 StackExchange.Redis.HybridCache@0.1.36-alpha
                    
#: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=StackExchange.Redis.HybridCache&version=0.1.36-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=StackExchange.Redis.HybridCache&version=0.1.36-alpha&prerelease
                    
Install as a Cake Tool

StackExchange.Redis.HybridCache

A HybridCache implementation built natively on StackExchange.Redis v4 server-assisted client-side caching, instead of layering the stock implementation over IDistributedCache.

Why: the stock pairing keeps two uncoordinated in-memory tiers (the multiplexer's client cache and a MemoryCache L1), and IDistributedCache has no change notification, so key and tag invalidation never reach other servers' L1. Redis has had the missing mechanism since 6.0 (CLIENT TRACKING); building directly on it gives one near cache and fleet-coherent invalidation, while keeping the parts of the stock implementation worth keeping — the stampede protection (query combination), the serialization pipeline, and the HybridCache contract itself (from Microsoft.Extensions.Caching.Abstractions; swapping in this implementation is a one-line DI change). Entries are plain redis strings with absolute expiry — sliding expiration is deliberately unsupported (it is incompatible with client-side caching; the design notes explain why) — and the payload envelope stays byte-compatible with the default implementation's, given the same serializer configuration.

Status: functional, pre-release. The full HybridCache surface is implemented at feature parity with the stock implementation — stampede protection (query combination with shared cancellation and immutable/mutable value semantics), all entry flags, key/tag validation, tag invalidation (push-coherent, server-assisted), logging and EventSource telemetry with the stock event IDs, TimeProvider support — and the stock test suites have been inherited and pass. See docs/design.md for architecture and remaining phases, and docs/parity-plan.md for the parity inventory and the deliberate divergences.

Usage

dotnet add package StackExchange.Redis.HybridCache --prerelease
var config = ConfigurationOptions.Parse("localhost:6379");
config.Protocol = RedisProtocol.Resp3;
config.ClientCache = new CacheOptions { Prefixes = ["hc:"] }; // match KeyPrefix

services.AddSingleton<IConnectionMultiplexer>(await ConnectionMultiplexer.ConnectAsync(config));
services.AddRedisHybridCache(); // registers HybridCache; KeyPrefix defaults to "hc:"
public class SomeService(HybridCache cache)
{
    public async Task<Customer> GetCustomerAsync(int id, CancellationToken ct = default)
        => await cache.GetOrCreateAsync(
            $"customer/{id}",
            async token => await LoadFromDatabaseAsync(id, token),
            tags: ["customers"],
            cancellationToken: ct);
}

Reads served from the client cache are local, synchronous and allocation-free; RemoveAsync and RemoveByTagAsync invalidate every server's near cache via redis push invalidation. A dedicated multiplexer for the cache is encouraged (client-side caching is connection-level) — register it keyed with typeof(HybridCache) and it is preferred automatically. See docs/usage.md for configuration, degraded modes, serialization, and telemetry.

Layout

  • src/StackExchange.Redis.HybridCache/ — the library (RedisHybridCache : HybridCache, options, DI registration)
  • tests/StackExchange.Redis.HybridCache.Tests/ — xunit.v3 on Microsoft.Testing.Platform
  • docs/design.md — design notes

A runnable active-vs-passive invalidation demo (this implementation against the in-box HybridCache, console and interactive TUI) lives in the demos repo.

Building

dotnet build
dotnet test

Requires the .NET 10 SDK (see global.json). Versioning is Nerdbank.GitVersioning (version.json); packages are produced from src/.

License

MIT. Portions are derived from dotnet/extensions (Microsoft.Extensions.Caching.Hybrid), also MIT — see THIRD-PARTY-NOTICES.md.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.36-alpha 0 11/13/2026
0.1.29-alpha 35 11/12/2026