Resrcify.SharedKernel.Caching
4.4.0
See the version list below for details.
dotnet add package Resrcify.SharedKernel.Caching --version 4.4.0
NuGet\Install-Package Resrcify.SharedKernel.Caching -Version 4.4.0
<PackageReference Include="Resrcify.SharedKernel.Caching" Version="4.4.0" />
<PackageVersion Include="Resrcify.SharedKernel.Caching" Version="4.4.0" />
<PackageReference Include="Resrcify.SharedKernel.Caching" />
paket add Resrcify.SharedKernel.Caching --version 4.4.0
#r "nuget: Resrcify.SharedKernel.Caching, 4.4.0"
#:package Resrcify.SharedKernel.Caching@4.4.0
#addin nuget:?package=Resrcify.SharedKernel.Caching&version=4.4.0
#tool nuget:?package=Resrcify.SharedKernel.Caching&version=4.4.0
Resrcify.SharedKernel.Caching
Resrcify.SharedKernel.Caching provides an IDistributedCache-based caching service with typed serialization helpers and simple expiration APIs.
Table of Contents
What you get
ICachingServiceabstraction inResrcify.SharedKernel.Abstractions.Caching.DistributedCachingServiceimplementation inPrimitives/, registered withservices.AddDistributedCaching()(Extensions/).- Typed JSON serialization via
System.Text.Json. - Support for:
- Sliding expiration (
TimeSpan) - Absolute expiration (
DateTimeOffset) - Bulk retrieval by keys (
GetBulkAsync<T>) - Claims (
IClaimStore.TryClaimForAsync): set a key only if nobody holds it
- Sliding expiration (
- Values serialized with the caller's
JsonSerializerOptions(indentation and escaping too).
Prerequisites
- .NET 10 SDK.
- A configured
IDistributedCacheprovider (memory, Redis, SQL Server, etc.).
Install
Option A: Project reference
<ProjectReference Include="..\path\to\Resrcify.SharedKernel.Caching.csproj" />
Option B: NuGet package
<PackageReference Include="Resrcify.SharedKernel.Caching" Version="<latest>" />
CLI:
dotnet add package Resrcify.SharedKernel.Caching
Quick Start
using Resrcify.SharedKernel.Caching.Extensions;
services.AddDistributedCaching();
// or, tuning the in-memory cache:
services.AddDistributedCaching(cache => cache.SizeLimit = 1024 * 1024 * 1024);
AddDistributedCaching registers, in one call: the in-memory IDistributedCache (AddDistributedMemoryCache, which
configure tunes) unless one is registered already (Redis, registered before it, is kept); DistributedCachingService
as the ICachingService and the IClaimStore, one singleton (the mediator's idempotency behavior and the message
bus' duplicate skipping claim keys through it); and the system TimeProvider unless one is registered (before or
after). An ICachingService or IClaimStore registered before is kept. It replaces:
services.AddDistributedMemoryCache();
services.AddSingleton<ICachingService, DistributedCachingService>();
Usage guide
Set cache values
Every entry expires, and how long it lives is in the method's name:
| Call | The entry is kept |
|---|---|
SetForAsync(key, value, TimeSpan expiresIn) |
for expiresIn from now; reads don't extend it |
SetAsync(key, value, DateTimeOffset absoluteExpiration) |
until that time |
SetSlidingAsync(key, value, TimeSpan slidingExpiration) |
while it is read at least every slidingExpiration |
// A one-time code: gone after 5 minutes, however often it is read.
await cachingService.SetForAsync($"otc:{email}", code, TimeSpan.FromMinutes(5), cancellationToken);
// A user profile: kept while it is in use.
await cachingService.SetSlidingAsync("users:42", userDto, TimeSpan.FromMinutes(10), cancellationToken);
An implementation provides one method, SetAsync(key, value, absoluteExpiration, slidingExpiration, serializerOptions, cancellationToken); the others call it. It refuses an entry with neither expiration: one that
never expires stays until the cache runs out of memory. Data kept until the next update replaces it gets a lifetime
longer than the update interval, and its readers handle it being gone.
Get cache values
UserDto? cachedUser = await cachingService.GetAsync<UserDto>(
key: "users:42",
cancellationToken: cancellationToken);
Remove values and bulk get
await cachingService.RemoveAsync(
key: "users:42",
cancellationToken: cancellationToken);
IEnumerable<UserDto?> cachedUsers = await cachingService.GetBulkAsync<UserDto>(
keys: ["users:1", "users:2", "users:3"],
cancellationToken: cancellationToken);
Claim a key (do something once)
// IClaimStore claims (DistributedCachingService is one)
if (await claims.TryClaimForAsync("payouts:sent:42", TimeSpan.FromHours(3), cancellationToken))
{
// this caller holds the claim; release it with ReleaseAsync if the work must be retried
}
A claim is a marker, not a value: claims are a separate interface (IClaimStore) from the cache, and a claim key is
never read with GetAsync or written with SetAsync. DistributedCachingService claims atomically within one process only (IDistributedCache
can't set a key only if it is absent): two instances sharing a cache can both claim a key. An ICachingService over
Redis can claim across processes with SET key value PX <ms> NX.
Common issues
- If cache entries never expire, verify the provider supports requested expiration settings.
- If deserialization fails, ensure cached payload schema matches the expected type.
- If performance degrades on bulk operations, review provider latency and key count per request.
Related modules
Resrcify.SharedKernel.MediatorincludesCachingPipelineBehavior<TRequest, TResponse>for cache-aside query handling.
| 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
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Caching.Memory (>= 10.0.13)
- Resrcify.SharedKernel.Abstractions (>= 4.4.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Resrcify.SharedKernel.Caching:
| Package | Downloads |
|---|---|
|
Resrcify.SharedKernel.Messaging
Implements custom messaging abstractions with support for request/notification dispatching and pipeline behaviors. |
|
|
Resrcify.SharedKernel.PerformanceTests
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.4.1 | 0 | 10/17/2026 |
| 4.4.0 | 44 | 10/16/2026 |
| 4.3.0 | 64 | 10/16/2026 |
| 4.2.0 | 74 | 10/14/2026 |
| 4.1.0 | 60 | 10/14/2026 |
| 4.0.0 | 106 | 10/13/2026 |
| 3.0.0 | 191 | 10/3/2026 |
| 2.2.0 | 180 | 9/13/2026 |
| 2.1.1 | 1,524 | 6/8/2026 |
| 2.1.0 | 154 | 5/24/2026 |
| 2.0.0 | 182 | 5/22/2026 |
| 1.16.3 | 284 | 5/7/2026 |
| 1.16.2 | 150 | 5/7/2026 |
| 1.16.1 | 143 | 5/7/2026 |
| 1.16.0 | 151 | 5/7/2026 |
| 1.15.0 | 291 | 4/18/2026 |
| 1.14.0 | 426 | 10/15/2025 |
| 1.13.0 | 499 | 6/27/2025 |
| 1.12.0 | 405 | 4/16/2025 |
| 1.11.0 | 287 | 4/15/2025 |