MonadicSharp.Caching
1.0.0
dotnet add package MonadicSharp.Caching --version 1.0.0
NuGet\Install-Package MonadicSharp.Caching -Version 1.0.0
<PackageReference Include="MonadicSharp.Caching" Version="1.0.0" />
<PackageVersion Include="MonadicSharp.Caching" Version="1.0.0" />
<PackageReference Include="MonadicSharp.Caching" />
paket add MonadicSharp.Caching --version 1.0.0
#r "nuget: MonadicSharp.Caching, 1.0.0"
#:package MonadicSharp.Caching@1.0.0
#addin nuget:?package=MonadicSharp.Caching&version=1.0.0
#tool nuget:?package=MonadicSharp.Caching&version=1.0.0
MonadicSharp.Caching
Result-aware caching for AI agent pipelines — cache misses and errors are typed
Result<T>values, never null or exceptions.
Overview
MonadicSharp.Caching integrates caching into Railway-Oriented pipelines:
ICacheService— unified Result-aware interface for memory and distributed cachesMemoryCacheService— backed byIMemoryCache, serializes via JSONDistributedCacheService— backed byIDistributedCache(Redis, SQL Server, etc.)CachingAgentWrapper— transparent decorator: caches agent output for identical inputsAgentCachePolicy— configurable key factory, TTL, bypass predicate
Installation
dotnet add package MonadicSharp.Caching
ICacheService
// Get — returns CacheError.Miss on miss, never null
Result<UserProfile> cached = await cache.GetAsync<UserProfile>("user:42");
// Set
await cache.SetAsync("user:42", profile, new CacheEntryOptions
{
AbsoluteExpiration = TimeSpan.FromMinutes(10)
});
// Remove (idempotent — removing a missing key is always Success)
await cache.RemoveAsync("user:42");
// GetOrSet — the Railway-friendly pattern
var result = await cache.GetOrSetAsync(
key: $"user:{userId}",
factory: ct => repository.FindAsync(userId, ct),
options: CacheEntryOptions.WithTtl(TimeSpan.FromMinutes(5)));
CacheEntryOptions
// Absolute TTL
CacheEntryOptions.WithTtl(TimeSpan.FromMinutes(10))
// Sliding TTL (reset on each access)
new CacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(5) }
// Size (for IMemoryCache with size limits)
new CacheEntryOptions { Size = 1 }
CachingAgentWrapper
Wraps any IAgent<TInput, TOutput> with transparent output caching.
IAgent<Query, SearchResult> cachedSearch = new CachingAgentWrapper<Query, SearchResult>(
inner: searchAgent,
cache: cache,
policy: new AgentCachePolicy<Query, SearchResult>
{
// Key derivation from agent name + input
KeyFactory = (name, q) => $"{name}:{q.Text}:{q.TopK}",
// Cache TTL
EntryOptions = CacheEntryOptions.WithTtl(TimeSpan.FromMinutes(10)),
// Only cache successful results (default: true)
CacheOnlySuccesses = true,
// Skip cache for certain inputs
BypassPredicate = (q, ctx) => q.SkipCache
});
The wrapper exposes the same Name and RequiredCapabilities as the inner agent — it is completely transparent to the pipeline.
DI Registration
// IMemoryCache-backed (in-process)
services.AddMonadicSharpMemoryCache();
// IDistributedCache-backed (Redis, SQL Server, etc.)
services.AddStackExchangeRedisCache(opts => opts.Configuration = "localhost");
services.AddMonadicSharpDistributedCache();
Error Codes
| Code | Meaning |
|---|---|
CACHE_MISS |
Key not found in cache |
CACHE_DESERIALIZATION_FAILED |
Cached bytes could not be deserialized |
CACHE_SERIALIZATION_FAILED |
Value could not be serialized before storing |
CACHE_STORE_ERROR |
Underlying cache store threw an exception |
License
MIT — part of MonadicSharp.Framework.
| 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
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- MonadicSharp (>= 1.4.0)
- MonadicSharp.Agents (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MonadicSharp.Caching:
| Package | Downloads |
|---|---|
|
MonadicSharp.Framework
Meta-package for the MonadicSharp Framework — install this single package to get Agents, Caching, Http, Persistence, Security, and Telemetry in one shot. For à-la-carte usage, reference individual MonadicSharp.* packages instead. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 39 | 3/3/2026 |