GM.Caching.Redis
1.0.0
dotnet add package GM.Caching.Redis --version 1.0.0
NuGet\Install-Package GM.Caching.Redis -Version 1.0.0
<PackageReference Include="GM.Caching.Redis" Version="1.0.0" />
<PackageVersion Include="GM.Caching.Redis" Version="1.0.0" />
<PackageReference Include="GM.Caching.Redis" />
paket add GM.Caching.Redis --version 1.0.0
#r "nuget: GM.Caching.Redis, 1.0.0"
#:package GM.Caching.Redis@1.0.0
#addin nuget:?package=GM.Caching.Redis&version=1.0.0
#tool nuget:?package=GM.Caching.Redis&version=1.0.0
<p align="center"> <img src="https://raw.githubusercontent.com/gmetskhvarishvili/GM.Caching/master/icon.png" alt="GM.Caching" width="140" height="140" /> </p>
GM.Caching
A small, provider-agnostic caching abstraction for .NET. Depend on one interface —
ICacheService — with typed get/set, GetOrCreateAsync (single-flight, no cache stampede),
and absolute/sliding expiration. Ships an in-memory implementation; add a distributed backend with
GM.Caching.Redis. Targets .NET 10.
Packages
The two packages version and release together (lockstep):
| Package | What it gives you |
|---|---|
GM.Caching |
ICacheService, CacheEntryOptions, and an in-memory implementation over IMemoryCache (AddGMCaching()). |
GM.Caching.Redis |
A Redis implementation over StackExchange.Redis (AddGMRedisCaching()) — same interface, distributed. |
dotnet add package GM.Caching # in-memory
dotnet add package GM.Caching.Redis # + Redis backend
Quick start
In-memory
using GM.Caching;
builder.Services.AddGMCaching(); // optionally: o => o.KeyPrefix = "myapp:"
Redis
using GM.Caching.Redis;
builder.Services.AddGMRedisCaching(o =>
{
o.ConnectionString = "localhost:6379";
o.KeyPrefix = "myapp:";
});
// or bind from configuration: builder.Services.AddGMRedisCaching(builder.Configuration, "Redis");
Use it
Inject ICacheService — the same code works with either backend:
public class WeatherService(ICacheService cache, IWeatherApi api)
{
public Task<Forecast> GetAsync(string city) =>
cache.GetOrCreateAsync(
$"forecast:{city}",
ct => api.FetchAsync(city, ct),
CacheEntryOptions.Absolute(TimeSpan.FromMinutes(10)));
}
GetOrCreateAsync is single-flight: if many callers ask for the same missing key at once, the
factory runs once and everyone gets that result — no stampede on your database or upstream API.
The interface
Task<T?> GetAsync<T>(string key, CancellationToken ct = default);
Task SetAsync<T>(string key, T value, CacheEntryOptions? options = null, CancellationToken ct = default);
Task<T> GetOrCreateAsync<T>(string key, Func<CancellationToken, Task<T>> factory, CacheEntryOptions? options = null, CancellationToken ct = default);
Task<bool> ExistsAsync(string key, CancellationToken ct = default);
Task RemoveAsync(string key, CancellationToken ct = default);
CacheEntryOptions.Absolute(ttl) / CacheEntryOptions.Sliding(window) set per-entry expiration;
CacheServiceOptions.KeyPrefix and DefaultAbsoluteExpiration apply provider-wide. The Redis
provider JSON-serializes values and refreshes the key TTL on read for sliding entries.
Repository layout
GM.Caching/ # ICacheService, options, in-memory implementation
GM.Caching.Redis/ # Redis implementation (StackExchange.Redis)
tests/GM.Caching.Tests/ # xUnit tests for the in-memory cache
Building & testing
dotnet build -c Release
dotnet test -c Release
Releasing
Versioning is automated from Conventional Commits —
see CONTRIBUTING.md. Both packages share one version (Directory.Build.props)
and publish together to nuget.org on each release.
License
MIT — see LICENSE.
| 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
- GM.Caching (>= 1.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Options (>= 10.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.0)
- StackExchange.Redis (>= 2.13.17)
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 | 98 | 8/2/2026 |