Pragmatic.Caching
1.0.0-alpha.6
dotnet add package Pragmatic.Caching --version 1.0.0-alpha.6
NuGet\Install-Package Pragmatic.Caching -Version 1.0.0-alpha.6
<PackageReference Include="Pragmatic.Caching" Version="1.0.0-alpha.6" />
<PackageVersion Include="Pragmatic.Caching" Version="1.0.0-alpha.6" />
<PackageReference Include="Pragmatic.Caching" />
paket add Pragmatic.Caching --version 1.0.0-alpha.6
#r "nuget: Pragmatic.Caching, 1.0.0-alpha.6"
#:package Pragmatic.Caching@1.0.0-alpha.6
#addin nuget:?package=Pragmatic.Caching&version=1.0.0-alpha.6&prerelease
#tool nuget:?package=Pragmatic.Caching&version=1.0.0-alpha.6&prerelease
Pragmatic.Caching
Source-generated caching for .NET 10: typed keys, tag-based invalidation, category routing, and HybridCache integration.
The Problem
Caching in .NET means scattered magic strings, manual serialization, hardcoded TTLs, and ad-hoc invalidation:
var key = $"product:{id}"; // magic string: rename and it breaks
var cached = await cache.GetStringAsync(key, ct);
if (cached is not null) return JsonSerializer.Deserialize<ProductDto>(cached);
var dto = ProductDto.FromEntity(await repo.GetByIdAsync(id, ct));
await cache.SetStringAsync(key, JsonSerializer.Serialize(dto),
new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(5) }, ct);
Miss one key in the invalidation handler and you serve stale data; share a backend across subsystems and you get key collisions.
The Solution
Declare what to cache and when to invalidate; the generator produces the key construction, options, and invalidation at compile time.
[Query<Product, ProductDto>(Single = true)]
[Cacheable(Duration = "5m", Tags = ["products", "product:{ProductId}"])]
public partial class GetProductQuery { public required Guid ProductId { get; init; } }
// A mutation invalidates by tag: no key-pattern duplication
[Mutation(Mode = MutationMode.Update)]
[InvalidatesCache("products")]
public partial class UpdateProductMutation : Mutation<Product> { /* ... */ }
Typed keys (no magic strings), tag-based invalidation, category routing to isolate subsystems (permissions, rate limiting, output cache) on a shared backend, and HybridCache (in-memory + distributed) integration.
Distributed atomic counters (Redis)
ICacheStack.IncrementAsync is atomic per process with the default HybridCacheStack: enough for
single-instance rate limiting, not for a multi-node deployment. The Pragmatic.Caching.Redis package
routes counters to Redis (one atomic INCRBY+PEXPIRE Lua script), leaving every other cache
operation on the existing backend:
services.AddPragmaticCaching();
services.AddRedisAtomicCounters("localhost:6379"); // or pre-register IConnectionMultiplexer
With this in place the endpoints' [RateLimit] limiter enforces limits strictly across instances.
Redis failures propagate (no silent per-instance fallback); the rate limiter fails closed.
Installation
dotnet add package Pragmatic.Caching
dotnet add package Pragmatic.SourceGenerator # generates keys + invalidation
Status
Functional within 1.0.0-alpha: [Cacheable]/[InvalidatesCache], typed keys, tag invalidation,
category routing, and the HybridCache integration. See the roadmap.
Documentation
| Guide | What you'll learn |
|---|---|
| Concepts | Typed keys, tags, invalidation model, HybridCache |
| Getting Started | Cache a query, invalidate on a mutation |
| Categories | Category routing to isolate subsystems on a shared backend |
| Common Mistakes | The most frequent caching pitfalls |
| Troubleshooting | Problem/solution guide with diagnostics |
Requirements
- .NET 10.0+
Pragmatic.SourceGeneratoranalyzer
License
Part of the Pragmatic.Design ecosystem. See Licensing. Pragmatic.Caching is MIT-licensed.
| 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. net11.0 is compatible. |
-
net10.0
- Microsoft.Extensions.Caching.Hybrid (>= 10.8.0)
- Pragmatic.Abstractions (>= 1.0.0-alpha.6)
- Pragmatic.Ensure (>= 1.0.0-alpha.6)
- Pragmatic.Result (>= 1.0.0-alpha.6)
-
net11.0
- Microsoft.Extensions.Caching.Hybrid (>= 10.8.0)
- Pragmatic.Abstractions (>= 1.0.0-alpha.6)
- Pragmatic.Ensure (>= 1.0.0-alpha.6)
- Pragmatic.Result (>= 1.0.0-alpha.6)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Pragmatic.Caching:
| Package | Downloads |
|---|---|
|
Pragmatic.Actions
DomainAction pattern with Pipeline, Filters, and Boundary support. Zero reflection, compile-time safe, source-generated. |
|
|
Pragmatic.Endpoints.AspNetCore
ASP.NET Core integration for Pragmatic.Endpoints: EndpointContext, error-to-ProblemDetails conversion, and file response handling. |
|
|
Pragmatic.Persistence.EFCore
Entity Framework Core implementation for Pragmatic.Persistence. DbContext, Repository implementations, and EF-specific features. |
|
|
Pragmatic.Caching.Redis
Redis for Pragmatic.Caching across hosts: atomic counters (ICacheStack.IncrementAsync via a single Lua INCRBY+PEXPIRE script) and the invalidation broadcast that makes every host drop what one host invalidated. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.6 | 303 | 11/21/2026 |
| 1.0.0-alpha.5 | 234 | 11/21/2026 |
| 1.0.0-alpha.4 | 289 | 11/16/2026 |
| 1.0.0-alpha.3 | 624 | 10/17/2026 |
| 1.0.0-alpha.2 | 236 | 10/12/2026 |
| 1.0.0-alpha.1 | 451 | 10/3/2026 |