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

<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

CI NuGet License: MIT

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 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
1.0.0 98 8/2/2026