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
<PackageReference Include="Kck.Caching.Hybrid" Version="5.0.0" />
<PackageVersion Include="Kck.Caching.Hybrid" Version="5.0.0" />
<PackageReference Include="Kck.Caching.Hybrid" />
paket add Kck.Caching.Hybrid --version 5.0.0
#r "nuget: Kck.Caching.Hybrid, 5.0.0"
#:package Kck.Caching.Hybrid@5.0.0
#addin nuget:?package=Kck.Caching.Hybrid&version=5.0.0
#tool nuget:?package=Kck.Caching.Hybrid&version=5.0.0
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 | 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
- Kck.Caching.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Caching.Hybrid (>= 10.11.0)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 10.0.14)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.14)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.14)
- StackExchange.Redis (>= 3.4.20)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.