Kck.Caching.Hybrid 5.0.0

dotnet add package Kck.Caching.Hybrid --version 5.0.0
                    
NuGet\Install-Package Kck.Caching.Hybrid -Version 5.0.0
                    
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="Kck.Caching.Hybrid" Version="5.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kck.Caching.Hybrid" Version="5.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Kck.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 Kck.Caching.Hybrid --version 5.0.0
                    
#r "nuget: Kck.Caching.Hybrid, 5.0.0"
                    
#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 Kck.Caching.Hybrid@5.0.0
                    
#: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=Kck.Caching.Hybrid&version=5.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Kck.Caching.Hybrid&version=5.0.0
                    
Install as a Cake Tool

Kck.Caching.Hybrid

Two-level hybrid cache provider combining an in-process L1 memory cache with a distributed L2 Redis cache for optimal read performance. Redis is required (ExistsAsync and RemoveByPrefixAsync use it); without Redis, use Kck.Caching.InMemory.

Installation

dotnet add package Kck.Caching.Hybrid

Quick Start

// Program.cs - L1 in memory, L2 Redis (Microsoft.Extensions.Caching.Hybrid)
builder.Services.AddKckCachingHybrid(
    redis => redis.Configuration = "localhost:6379",
    hybrid =>
    {
        hybrid.KeyPrefix = "myapp:";
        hybrid.DefaultExpiration = TimeSpan.FromMinutes(30);
        hybrid.DefaultLocalExpiration = TimeSpan.FromMinutes(5);
    });

// Usage
public class ProductService(ICacheService cache, IProductRepository products)
{
    public Task<Product?> GetAsync(int id, CancellationToken ct) =>
        cache.GetOrSetAsync($"product:{id}", () => products.FindAsync(id, ct), TimeSpan.FromMinutes(10), ct);

    public Task InvalidateAllAsync(CancellationToken ct) => cache.RemoveByPrefixAsync("product:", ct);
}

Configuration

First callback: RedisCacheOptions for the L2 Redis cache (Configuration, ConfigurationOptions or ConnectionMultiplexerFactory; registration throws when none is set). The Redis connection is opened asynchronously when the host starts, as in Kck.Caching.Redis; resolving ICacheService before the host's StartAsync completed throws. Second callback:

Property Description Default
KeyPrefix Prefix prepended to every cache key null
DefaultExpiration L1 + L2 expiration 5 minutes
DefaultLocalExpiration L1 (in-memory) expiration, at most DefaultExpiration 1 minute

Resources

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

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
5.0.0 268 11/2/2026
4.8.0 578 10/31/2026
Loading failed