Muonroi.Caching.Abstractions
1.0.0-alpha.16
dotnet add package Muonroi.Caching.Abstractions --version 1.0.0-alpha.16
NuGet\Install-Package Muonroi.Caching.Abstractions -Version 1.0.0-alpha.16
<PackageReference Include="Muonroi.Caching.Abstractions" Version="1.0.0-alpha.16" />
<PackageVersion Include="Muonroi.Caching.Abstractions" Version="1.0.0-alpha.16" />
<PackageReference Include="Muonroi.Caching.Abstractions" />
paket add Muonroi.Caching.Abstractions --version 1.0.0-alpha.16
#r "nuget: Muonroi.Caching.Abstractions, 1.0.0-alpha.16"
#:package Muonroi.Caching.Abstractions@1.0.0-alpha.16
#addin nuget:?package=Muonroi.Caching.Abstractions&version=1.0.0-alpha.16&prerelease
#tool nuget:?package=Muonroi.Caching.Abstractions&version=1.0.0-alpha.16&prerelease
Muonroi.Caching.Abstractions
Caching contracts —
IMCacheService,CacheEntryOptions, and cache key conventions — for Muonroi applications.
This package is the contracts-only layer of the Muonroi caching stack. It defines the IMCacheService interface, the CacheEntryOptions record, the DistributedCacheKeyBuilder static helper, and the telemetry surface. There is no runtime behavior in this package — all implementations live in Muonroi.Caching.Memory (in-process + multi-level) and Muonroi.Caching.Redis (distributed Redis backend).
Reference this package directly when authoring a library that depends on the caching abstractions without coupling to a specific backend.
Installation
dotnet add package Muonroi.Caching.Abstractions --prerelease
Quick Start
This package ships contracts only. To get a working cache you depend on an implementation package and consume IMCacheService or IMultiLevelCacheService via DI.
Implement IMCacheService in a custom backend
using Muonroi.Caching.Abstractions.Distributed;
public sealed class MyCustomCacheService : IMCacheService
{
public Task<T?> GetAsync<T>(string key, CancellationToken token = default)
=> /* your storage read */ Task.FromResult(default(T?));
public Task SetAsync<T>(string key, T value, CacheEntryOptions? options = null,
CancellationToken token = default)
=> /* your storage write */ Task.CompletedTask;
public Task RemoveAsync(string key, CancellationToken token = default)
=> /* your storage delete */ Task.CompletedTask;
public Task RefreshAsync(string key, CancellationToken token = default)
=> /* slide TTL */ Task.CompletedTask;
public Task<T?> GetOrSetAsync<T>(string key, Func<Task<T?>> factory,
CacheEntryOptions? options = null, CancellationToken token = default) where T : class
=> /* check then factory */ factory();
}
Consume IMCacheService with CacheEntryOptions
using Muonroi.Caching.Abstractions.Distributed;
// Injected by the implementation package's DI registration
public class OrderRepository(IMCacheService cache)
{
public async Task<Order?> GetAsync(int orderId, CancellationToken token)
{
string key = DistributedCacheKeyBuilder.Build(
key: $"order:{orderId}",
keyNamespace: "orders");
return await cache.GetOrSetAsync<Order>(
key,
factory: async () => await LoadFromDatabaseAsync(orderId, token),
options: new CacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30),
KeyNamespace = "orders",
TenantScoped = true // key includes the current tenant id
},
token);
}
}
See the Quickstart.Caching sample for a full working example using Muonroi.Caching.Memory.
Features
IMCacheService— unified distributed cache interface:GetAsync,SetAsync,RemoveAsync,RefreshAsync,GetOrSetAsync(cache-aside with factory)CacheEntryOptions— immutable record withAbsoluteExpirationRelativeToNow(default 24 h),SlidingExpiration,KeyNamespace, andTenantScoped(defaulttrue)DistributedCacheKeyBuilder— composes structured cache keys in{namespace}:{tenantId}:{baseKey}form;NormalizeTenantIdtrims and null-coalesces blank inputDistributedCacheTelemetryDescriptor—ITelemetryDescriptorthat exposes the Activity source and Meter names for wiring into OpenTelemetryDistributedCacheRuntimeTelemetry— static helpers (ActivitySource,TrackOperation) for recording operation counts, error counts, and latency histograms
Configuration
This package carries no DI registration. Configuration and DI wiring are provided by the implementation packages:
Muonroi.Caching.Memory— callbuilder.Services.AddMultiLevelCaching(builder.Configuration)to registerIMultiLevelCacheService(in-process + optional distributed layer)Muonroi.Caching.Redis— registersIMCacheServicebacked by Redis; see that package's README for theappsettings.jsonCachesection
API Reference
| Type | Purpose |
|---|---|
IMCacheService |
Core distributed cache contract: get, set, remove, refresh, get-or-set |
CacheEntryOptions |
Immutable options record controlling TTL, sliding expiry, key namespace, and tenant scoping |
DistributedCacheKeyBuilder |
Static helper that builds {namespace}:{tenantId}:{key} composite keys |
DistributedCacheTelemetryDescriptor |
ITelemetryDescriptor exposing the Activity source and Meter names |
DistributedCacheRuntimeTelemetry |
Static metrics surface: TrackOperation records counters and latency histograms |
Samples
- Quickstart.Caching — end-to-end demo of all cache operations (get-or-set, set, direct get, eviction, warming, key builder) using
Muonroi.Caching.Memory
Compatibility
- Target framework:
net8.0 - License: Apache-2.0 (OSS)
Related Packages
Muonroi.Caching.Memory— implementsIMultiLevelCacheServicewith in-process L1 + optional distributed L2Muonroi.Caching.Redis— implementsIMCacheServicewith a Redis distributed backendMuonroi.Core.Abstractions— foundational guards and interfaces referenced by this package
License
Apache-2.0. See LICENSE-APACHE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- Muonroi.Core.Abstractions (>= 1.0.0-alpha.16)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Muonroi.Caching.Abstractions:
| Package | Downloads |
|---|---|
|
Muonroi.Mediator
Mediator pattern implementation for Muonroi: command/query dispatching, pipeline behaviors, and validation integration. |
|
|
Muonroi.Caching.Memory
Multi-level in-memory + distributed cache implementation with tenant-aware key isolation and stampede protection. |
|
|
Muonroi.Auth
JWT authentication infrastructure: token validation, DPoP binding, claim extraction, and Muonroi auth middleware. |
|
|
Muonroi.AspNetCore
ASP.NET Core integration: auto-CRUD controllers, middleware pipeline, license protection, and Muonroi hosting extensions. |
|
|
Muonroi.Tenancy.SiteProfile.Web
ASP.NET Core middleware and SignalR hot-reload for Muonroi.Tenancy.SiteProfile. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.16 | 170 | 6/22/2026 |
| 1.0.0-alpha.15 | 204 | 5/31/2026 |
| 1.0.0-alpha.14 | 189 | 5/15/2026 |
| 1.0.0-alpha.13 | 161 | 5/2/2026 |
| 1.0.0-alpha.12 | 110 | 4/2/2026 |
| 1.0.0-alpha.11 | 151 | 4/2/2026 |
| 1.0.0-alpha.9 | 94 | 3/30/2026 |
| 1.0.0-alpha.8 | 332 | 3/28/2026 |
| 1.0.0-alpha.7 | 81 | 3/27/2026 |
| 1.0.0-alpha.5 | 78 | 3/27/2026 |
| 1.0.0-alpha.4 | 73 | 3/27/2026 |
| 1.0.0-alpha.3 | 77 | 3/27/2026 |
| 1.0.0-alpha.2 | 72 | 3/26/2026 |
| 1.0.0-alpha.1 | 111 | 3/8/2026 |