Muonroi.Caching.Abstractions 1.0.0-alpha.16

This is a prerelease version of Muonroi.Caching.Abstractions.
dotnet add package Muonroi.Caching.Abstractions --version 1.0.0-alpha.16
                    
NuGet\Install-Package Muonroi.Caching.Abstractions -Version 1.0.0-alpha.16
                    
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="Muonroi.Caching.Abstractions" Version="1.0.0-alpha.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Muonroi.Caching.Abstractions" Version="1.0.0-alpha.16" />
                    
Directory.Packages.props
<PackageReference Include="Muonroi.Caching.Abstractions" />
                    
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 Muonroi.Caching.Abstractions --version 1.0.0-alpha.16
                    
#r "nuget: Muonroi.Caching.Abstractions, 1.0.0-alpha.16"
                    
#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 Muonroi.Caching.Abstractions@1.0.0-alpha.16
                    
#: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=Muonroi.Caching.Abstractions&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Muonroi.Caching.Abstractions&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Tool

Muonroi.Caching.Abstractions

Caching contracts — IMCacheService, CacheEntryOptions, and cache key conventions — for Muonroi applications.

NuGet License: Apache 2.0

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 with AbsoluteExpirationRelativeToNow (default 24 h), SlidingExpiration, KeyNamespace, and TenantScoped (default true)
  • DistributedCacheKeyBuilder — composes structured cache keys in {namespace}:{tenantId}:{baseKey} form; NormalizeTenantId trims and null-coalesces blank input
  • DistributedCacheTelemetryDescriptorITelemetryDescriptor that exposes the Activity source and Meter names for wiring into OpenTelemetry
  • DistributedCacheRuntimeTelemetry — 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 — call builder.Services.AddMultiLevelCaching(builder.Configuration) to register IMultiLevelCacheService (in-process + optional distributed layer)
  • Muonroi.Caching.Redis — registers IMCacheService backed by Redis; see that package's README for the appsettings.json Cache section

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)

License

Apache-2.0. See LICENSE-APACHE.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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