SaanSoft.TaggedCache 0.1.0

dotnet add package SaanSoft.TaggedCache --version 0.1.0
                    
NuGet\Install-Package SaanSoft.TaggedCache -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" 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" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="SaanSoft.TaggedCache" />
                    
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 --version 0.1.0
                    
#r "nuget: SaanSoft.TaggedCache, 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@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&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=SaanSoft.TaggedCache&version=0.1.0
                    
Install as a Cake Tool

SaanSoft.TaggedCache

A .NET library providing tag-based cache on top of IDistributedCache.

Cache entries can be tagged with one or more string labels, then invalidated in bulk by tag — without needing to track individual cache keys.

Overview

This package is the core library: it defines ITaggedCache, ITaggedCacheOptions, and the base classes used by all backend implementations. You will typically install one of the backend packages instead:

Backend Package
In-memory (dev/test) SaanSoft.TaggedCache.Memory
Redis SaanSoft.TaggedCache.StackExchangeRedis
AWS DynamoDB SaanSoft.TaggedCache.AwsDynamoDb

Usage

Once a backend is registered, inject ITaggedCache wherever you need it.

NOTE: As ITaggedCache extends IDistributedCache, any usages of IDistributedCache will work with the configured backend implementation, and references to IDistributedCache will still work as expected.

Get and set with tags

// Set a single item with tags
await cache.SetAsync("product:42", product, tags: ["products", "category:electronics"]);

// Get a typed item
var product = await cache.GetAsync<Product>("product:42");

// Get an item, and if it doesn't exist in cache - create it, set in the cache and return the item
// NOTE: return type is `T?`, to handle the possibility of creating the item being null
//       null values are not cached
var products = await cache.GetOrCreateAsync<List<Product>>(
    cacheKey: "products",
    factory: ct => await db.GetProductsAsync(ct),
    tags: ["products"]
);

// Set multiple items at once
await cache.SetManyAsync([
    new TaggedCacheItem<Product>("product:1", p1) { Tags = ["products"] },
    new TaggedCacheItem<Product>("product:2", p2) { Tags = ["products"] },
]);

Invalidate by tag

// Remove all cache entries tagged "products"
await cache.RemoveByTagAsync("products");

// Remove all cache entries matching any of the given tags
await cache.RemoveByAnyTagAsync(["products", "category:electronics"]);

Custom expiry

var options = new DistributedCacheEntryOptions
{
    AbsoluteExpirationRelativeToNow = TimeSpan.FromHours(1),
    SlidingExpiration = TimeSpan.FromMinutes(15)
};

await cache.SetAsync("user:99", user, options, tags: ["users"]);

Key normalisation

All cache keys and tags are trimmed and lowercased before use. Operations are case-insensitive.

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 (4)

Showing the top 4 NuGet packages that depend on SaanSoft.TaggedCache:

Package Downloads
SaanSoft.TaggedCache.Memory

Package Description

SaanSoft.TaggedCache.OutputCache

Package Description

SaanSoft.TaggedCache.StackExchangeRedis

Package Description

SaanSoft.TaggedCache.AwsDynamoDb

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 120 5/15/2026