MethodCache.Redis
1.0.0-rc.5
dotnet add package MethodCache.Redis --version 1.0.0-rc.5
NuGet\Install-Package MethodCache.Redis -Version 1.0.0-rc.5
<PackageReference Include="MethodCache.Redis" Version="1.0.0-rc.5" />
<PackageVersion Include="MethodCache.Redis" Version="1.0.0-rc.5" />
<PackageReference Include="MethodCache.Redis" />
paket add MethodCache.Redis --version 1.0.0-rc.5
#r "nuget: MethodCache.Redis, 1.0.0-rc.5"
#:package MethodCache.Redis@1.0.0-rc.5
#addin nuget:?package=MethodCache.Redis&version=1.0.0-rc.5&prerelease
#tool nuget:?package=MethodCache.Redis&version=1.0.0-rc.5&prerelease
MethodCache.Redis
Redis as MethodCache's distributed cache. Results are shared between application instances, and invalidations reach every instance's in-memory cache over Redis pub/sub.
Install it at the same version as MethodCache.
Usage
builder.Services.AddMethodCache(mc => mc.UseRedis("localhost:6379"));
With options:
builder.Services.AddMethodCache(mc => mc
.UseRedis(options => options.Configuration = "redis1:6379,redis2:6379,password=...")
.Distributed(options => options.KeyPrefix = "orders-api:")); // data and backplane use the same final prefix
To share a connection your app already has instead:
builder.Services.AddMethodCache(mc => mc.UseRedis(options =>
options.ConnectionMultiplexerFactory = sp => sp.GetRequiredService<IConnectionMultiplexer>()));
- Set
ConfigurationorConnectionMultiplexerFactory. Startup fails when neither is set, so a missing configuration section never makes MethodCache connect tolocalhost. - MethodCache keeps its own cache and connection, so your app's
IDistributedCacheand Redis settings are left alone. - The connection opens on first use, on the thread pool, so the application starts while Redis is down and a slow connect never holds up a call.
- MethodCache doesn't dispose a shared connection. Disposing the service provider removes MethodCache's own subscriptions.
How it works
- MethodCache reads Redis on an in-memory miss and writes new results to both.
- Invalidating a tag stores the time of the invalidation, and entries with that tag written before it are treated as missing, so no tag sets are kept in Redis. An older invalidation that arrives late never undoes a newer one.
- Every invalidation is also published on the
<prefix>invalidationschannel, so every instance drops its in-memory copies at once. - Pub/sub delivers nothing while a connection is down. When the instance is subscribed again, it clears its in-memory cache. Reconnecting retries after 1 second, then twice as long each time, up to 30 seconds.
Memory and eviction
Invalidations are stored as keys beside the entries. If Redis evicts one under memory pressure, the entries it
invalidated are served again until they expire. Set maxmemory-policy noeviction on the Redis MethodCache uses (or give
it a Redis of its own) and give it enough memory. The volatile-* policies, the default of some managed Redis
services, can evict them too. A full Redis with noeviction refuses writes, which MethodCache handles like an outage.
See
Keep invalidations from being evicted.
When Redis is down
MethodCache keeps answering from memory and your methods; Redis never fails or stalls a call. Each call is capped at
OperationTimeout (1 second), Redis is skipped for CircuitBreakerDuration (10 seconds) after a failure, and
invalidations are queued and retried instead of throwing. The first failure and the recovery are logged.
The distributed cache guide
covers outages, consistency between instances, serialization and the DistributedCacheOptions that tune all of this.
The exact behavior is in the
distributed cache reference.
Options
| Option | Default | Description |
|---|---|---|
Configuration |
none | StackExchange.Redis configuration string |
ConnectionMultiplexerFactory |
none | Returns an existing connection to share instead of opening one |
EnableBackplane |
true |
Send invalidations to other instances over pub/sub |
DistributedCacheOptions.KeyPrefix applies to values, invalidations and the channel. The first instance that uses a
prefix fixes its minimum TagRetention; a shorter setting fails at startup, so use a new prefix to lower it.
| 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
- MethodCache (= 1.0.0-rc.5)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 9.0.9)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.9)
- Microsoft.Extensions.Options (>= 9.0.9)
- StackExchange.Redis (>= 2.9.25)
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.0.0-rc.5 | 0 | 11/4/2026 |
| 1.0.0-rc.4 | 0 | 11/4/2026 |
| 1.0.0-rc.3 | 5 | 11/4/2026 |
| 1.0.0-rc.2 | 62 | 10/20/2026 |
| 1.0.0-rc.1 | 69 | 10/19/2026 |