SaanSoft.TaggedCache.StackExchangeRedis 0.1.0

dotnet add package SaanSoft.TaggedCache.StackExchangeRedis --version 0.1.0
                    
NuGet\Install-Package SaanSoft.TaggedCache.StackExchangeRedis -Version 0.1.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="SaanSoft.TaggedCache.StackExchangeRedis" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SaanSoft.TaggedCache.StackExchangeRedis" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SaanSoft.TaggedCache.StackExchangeRedis" />
                    
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 SaanSoft.TaggedCache.StackExchangeRedis --version 0.1.0
                    
#r "nuget: SaanSoft.TaggedCache.StackExchangeRedis, 0.1.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 SaanSoft.TaggedCache.StackExchangeRedis@0.1.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=SaanSoft.TaggedCache.StackExchangeRedis&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SaanSoft.TaggedCache.StackExchangeRedis&version=0.1.0
                    
Install as a Cake Tool

SaanSoft.TaggedCache.StackExchangeRedis

Redis backend for SaanSoft.TaggedCache — tag-based cache on top of IDistributedCache, backed by Redis via StackExchange.Redis.

Installation

dotnet add package SaanSoft.TaggedCache.StackExchangeRedis

Setup

You must register IConnectionMultiplexer yourself as well as calling AddRedisTaggedCache.

// Program.cs
var builder = WebApplication.CreateBuilder(args);

// Register the Redis connection (required)
builder.Services.AddSingleton<IConnectionMultiplexer>(
    ConnectionMultiplexer.Connect(builder.Configuration.GetConnectionString("Redis")!)
);

// Register the tagged cache
builder.Services.AddRedisTaggedCache();

var app = builder.Build();
app.Run();

Configuration

Pass a RedisTaggedCacheOptions instance to customise behaviour:

builder.Services.AddRedisTaggedCache(new RedisTaggedCacheOptions
{
    // Default expiry when none is specified in SetAsync calls
    DefaultCacheOptions = new DistributedCacheEntryOptions
    {
        AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10)
    },

    // Refresh a sliding-expiry entry when this fraction of its window remains
    SlidingRefreshThresholdFraction = 0.25,

    // Prefix added to tag storage keys (set to "" to disable)
    TagKeyPrefix = "tag:"
});

Available options

Property Default Description
DefaultCacheOptions 5 min absolute Expiry used when none is supplied to SetAsync
SlidingRefreshThresholdFraction 0.25 Fraction of sliding window remaining at which to proactively refresh; must be > 0 and <= 1
TagKeyPrefix "tag:" Prefix applied to tag storage keys in Redis
JsonSerializerOptions JsonSerializerDefaults.Web Controls serialisation of cached values

DI registration

ITaggedCache is registered as Scoped; all cache state lives in Redis. RedisTaggedCacheOptions is registered as Singleton. IDistributedCache is also registered, resolving to the ITaggedCache instance.

Usage

app.MapGet("/products/{id}", async (int id, ITaggedCache cache) =>
{
    var product = await cache.GetAsync<Product>($"product:{id}");
    if (product is null)
    {
        product = await db.GetProductAsync(id);
        await cache.SetAsync($"product:{id}", product, tags: ["products"]);
    }
    return product;
});

app.MapPost("/products/invalidate", async (ITaggedCache cache) =>
{
    await cache.RemoveByTagAsync("products");
});
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
0.1.0 74 5/15/2026