Dosaic.Plugins.Caching.Redis
1.2.41
dotnet add package Dosaic.Plugins.Caching.Redis --version 1.2.41
NuGet\Install-Package Dosaic.Plugins.Caching.Redis -Version 1.2.41
<PackageReference Include="Dosaic.Plugins.Caching.Redis" Version="1.2.41" />
<PackageVersion Include="Dosaic.Plugins.Caching.Redis" Version="1.2.41" />
<PackageReference Include="Dosaic.Plugins.Caching.Redis" />
paket add Dosaic.Plugins.Caching.Redis --version 1.2.41
#r "nuget: Dosaic.Plugins.Caching.Redis, 1.2.41"
#:package Dosaic.Plugins.Caching.Redis@1.2.41
#addin nuget:?package=Dosaic.Plugins.Caching.Redis&version=1.2.41
#tool nuget:?package=Dosaic.Plugins.Caching.Redis&version=1.2.41
Dosaic.Plugins.Caching.Redis
Dosaic.Plugins.Caching.Redis is a Dosaic plugin that provides distributed caching backed by Redis via StackExchange.Redis. It registers IDistributedCache in the DI container, adds an OpenTelemetry tracing instrumentation for Redis operations, and wires up a readiness health check. For local development it can transparently fall back to an in-memory cache without any infrastructure dependency.
Installation
dotnet add package Dosaic.Plugins.Caching.Redis
Or add a package reference manually:
<PackageReference Include="Dosaic.Plugins.Caching.Redis" Version="" />
Features
- Registers
IDistributedCachebacked by StackExchange.Redis with a single config property - In-memory fallback mode (
UseInMemory: true) for local development and testing — no Redis instance required - Automatic
abortConnect=falsesafety flag appended to the connection string when not already present - OpenTelemetry tracing instrumentation for every Redis command via
OpenTelemetry.Instrumentation.StackExchangeRedis - Readiness health check (
/health/readiness) that verifies Redis connectivity (skipped in in-memory mode) - Configuration-driven — no boilerplate, just add the plugin and configure the section
Configuration
The plugin binds to the redisCache section via the [Configuration("redisCache")] attribute on RedisCacheConfiguration.
RedisCacheConfiguration
| Property | Type | Default | Description |
|---|---|---|---|
UseInMemory |
bool |
false |
When true, uses an in-memory cache instead of Redis. Useful for local development. |
ConnectionString |
string |
(required) | StackExchange.Redis connection string (e.g. localhost:6379). Required unless UseInMemory is true. |
appsettings.yml — Redis (production)
redisCache:
useInMemory: false
connectionString: "redis-host:6379,password=s3cr3t,ssl=false"
appsettings.yml — in-memory (local development)
redisCache:
useInMemory: true
appsettings.json equivalent
{
"redisCache": {
"useInMemory": false,
"connectionString": "redis-host:6379,password=s3cr3t,ssl=false"
}
}
Note: When
UseInMemoryisfalse, theConnectionStringproperty is mandatory. The plugin will throw anArgumentExceptionat startup if it is missing or empty.
Note: If
abortConnect=falseis not present in the connection string, the plugin appends it automatically to prevent the application from crashing when Redis is temporarily unavailable at startup.
Usage
Registering the plugin
The plugin is discovered automatically by the Dosaic source generator — no manual registration is needed. Just make sure the package is referenced and the redisCache section is present in your configuration.
Injecting IDistributedCache
using Microsoft.Extensions.Caching.Distributed;
internal class OrderService(IDistributedCache cache)
{
private const string CacheKey = "orders:summary";
public async Task<string?> GetSummaryAsync(CancellationToken ct)
{
return await cache.GetStringAsync(CacheKey, ct);
}
public async Task SetSummaryAsync(string summary, CancellationToken ct)
{
var options = new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5)
};
await cache.SetStringAsync(CacheKey, summary, options, ct);
}
public async Task InvalidateSummaryAsync(CancellationToken ct)
{
await cache.RemoveAsync(CacheKey, ct);
}
}
Storing and retrieving complex objects
IDistributedCache works with raw bytes. Serialize with System.Text.Json for structured data:
using System.Text.Json;
using Microsoft.Extensions.Caching.Distributed;
internal class ProductCache(IDistributedCache cache)
{
private static readonly DistributedCacheEntryOptions DefaultOptions = new()
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10),
SlidingExpiration = TimeSpan.FromMinutes(2)
};
public async Task SetAsync<T>(string key, T value, CancellationToken ct = default)
{
var bytes = JsonSerializer.SerializeToUtf8Bytes(value);
await cache.SetAsync(key, bytes, DefaultOptions, ct);
}
public async Task<T?> GetAsync<T>(string key, CancellationToken ct = default)
{
var bytes = await cache.GetAsync(key, ct);
return bytes is null ? default : JsonSerializer.Deserialize<T>(bytes);
}
}
Injecting RedisCacheConfiguration
The RedisCacheConfiguration singleton is also registered in DI if you need to read the connection string elsewhere:
internal class RedisInfoService(RedisCacheConfiguration redisCacheConfiguration)
{
public string GetConnectionInfo()
=> redisCacheConfiguration.UseInMemory
? "Running with in-memory cache"
: $"Connected to Redis at {redisCacheConfiguration.ConnectionString}";
}
Health Checks
When UseInMemory is false, the plugin registers a Redis health check tagged with the readiness tag. This means the /health/readiness endpoint (provided by the Dosaic WebHost) will report Unhealthy if Redis is unreachable.
GET /health/readiness
{
"status": "Healthy",
"results": {
"redis": {
"status": "Healthy",
"description": null
}
}
}
No health check is registered in in-memory mode.
OpenTelemetry
When running in Redis mode, the plugin automatically adds StackExchangeRedis tracing instrumentation to the OpenTelemetry pipeline. Every Redis command (GET, SET, DEL, etc.) will appear as a span in your distributed trace, including the command name and target key.
No additional configuration is required — instrumentation is enabled as part of ConfigureServices.
Dependencies
| Package | Purpose |
|---|---|
Microsoft.Extensions.Caching.StackExchangeRedis |
IDistributedCache backed by Redis |
AspNetCore.HealthChecks.Redis |
Redis readiness health check |
OpenTelemetry.Instrumentation.StackExchangeRedis |
Distributed tracing for Redis commands |
OpenTelemetry.Extensions.Hosting |
OpenTelemetry hosting integration |
Dosaic.Hosting.Abstractions |
Dosaic plugin interfaces and attributes |
| 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
- AspNetCore.HealthChecks.Redis (>= 9.0.0)
- Chronos.Abstractions (>= 2.0.24)
- Dosaic.Hosting.Abstractions (>= 1.2.41)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 10.0.11)
- Microsoft.Extensions.Configuration (>= 10.0.11)
- Microsoft.Extensions.DependencyInjection (>= 10.0.11)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Options (>= 10.0.11)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.11)
- OpenTelemetry (>= 1.18.0)
- OpenTelemetry.Extensions.Hosting (>= 1.18.0)
- OpenTelemetry.Instrumentation.StackExchangeRedis (>= 1.18.0-beta.1)
- Vogen (>= 8.0.7)
- YamlDotNet (>= 18.1.0)
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 |
|---|---|---|
| 1.2.41 | 71 | 9/7/2026 |
| 1.2.40 | 79 | 8/27/2026 |
| 1.2.40-alpha.1 | 65 | 8/27/2026 |
| 1.2.39 | 75 | 8/25/2026 |
| 1.2.38 | 83 | 7/30/2026 |
| 1.2.37 | 80 | 7/14/2026 |
| 1.2.36 | 87 | 7/10/2026 |
| 1.2.35 | 114 | 6/19/2026 |
| 1.2.34 | 93 | 6/10/2026 |
| 1.2.33 | 90 | 6/2/2026 |
| 1.2.31 | 88 | 5/28/2026 |
| 1.2.30 | 82 | 5/7/2026 |
| 1.2.29 | 78 | 5/5/2026 |
| 1.2.28 | 91 | 4/30/2026 |
| 1.2.27 | 83 | 4/29/2026 |
| 1.2.26 | 81 | 4/29/2026 |
| 1.2.25 | 96 | 4/27/2026 |
| 1.2.24 | 81 | 4/21/2026 |
| 1.2.23 | 95 | 4/14/2026 |
| 1.2.22 | 90 | 4/10/2026 |