CoreSystem.Cache
3.1.0
dotnet add package CoreSystem.Cache --version 3.1.0
NuGet\Install-Package CoreSystem.Cache -Version 3.1.0
<PackageReference Include="CoreSystem.Cache" Version="3.1.0" />
<PackageVersion Include="CoreSystem.Cache" Version="3.1.0" />
<PackageReference Include="CoreSystem.Cache" />
paket add CoreSystem.Cache --version 3.1.0
#r "nuget: CoreSystem.Cache, 3.1.0"
#:package CoreSystem.Cache@3.1.0
#addin nuget:?package=CoreSystem.Cache&version=3.1.0
#tool nuget:?package=CoreSystem.Cache&version=3.1.0
⚡ CoreSystem.Cache
Production-ready distributed caching framework for .NET 8, 9 and 10
CoreSystem.Cache provides a unified cache abstraction with an execution pipeline, Memory caching, optional external cache storage with fallback, HTTP response caching, OpenTelemetry metrics, and tag-based invalidation.
The package targets .NET 8, .NET 9 and .NET 10, and ships an assembly for each of those frameworks.
✨ Features
- ✅ Memory cache provider
- ✅ Cache-Aside (
GetOrAddAsync) - ✅ Tag-based invalidation
- ✅ Optional external cache with Memory fallback
- ✅ HTTP response caching
- ✅ OpenTelemetry metrics for cache hits and misses
- ✅ Configurable execution pipeline
- ✅ Optional resilience integration through
Core.Resilience - ✅ Configurable serialization through
Core.Serialization
Redis support is provided by the CoreSystem.Cache.Redis package, which
registers Redis as the external primary storage and uses Memory as the
fallback storage.
📦 Installation
dotnet add package CoreSystem.Cache
For Redis support, add the Redis provider package separately:
dotnet add package CoreSystem.Cache.Redis
| Package | Responsibility |
|---|---|
| CoreSystem.Cache | Cache orchestration, storage resolution and fallback support |
| CoreSystem.Cache.Redis | Redis as the external primary storage, with Memory as the fallback |
| CoreSystem.Cache.Rehydration | Recovery of tracked fallback entries into the primary storage |
🚀 Quick Start
Register the framework:
builder.Services.AddCoreCache(options =>
{
options.InstanceName = "my-app";
});
Inject the cache service:
public sealed class ProductService(ICoreCache cache)
{
}
Store data:
await cache.SetAsync(
"products:1",
product,
TimeSpan.FromMinutes(10));
Retrieve data:
var product = await cache.GetAsync<Product>("products:1");
Recommended Cache-Aside pattern:
var product = await cache.GetOrAddAsync(
$"products:{id}",
async ct => await repository.GetByIdAsync(id, ct),
expiration: TimeSpan.FromMinutes(10),
tags: ["products"]);
🌐 HTTP Response Caching
Enable the middleware:
app.UseCoreCache();
Decorate your endpoint:
[Cacheable(expirationSeconds: 300)]
public async Task<IActionResult> Get(Guid id)
{
return Ok(await service.GetAsync(id));
}
HTTP response caching is applied only to endpoints decorated with
CacheableAttribute. The default request policy allows GET and HEAD
requests and excludes requests containing an Authorization header.
CacheOptions.DefaultExpiration sets the lifetime of a cached response when the
attribute omits expirationSeconds. It is not a fallback for SetAsync or
GetOrAddAsync: those operations store the entry with no expiration when the
expiration argument is null, so pass one explicitly when a lifetime is
needed.
📊 Why CoreSystem.Cache?
| Capability | IDistributedCache |
CoreSystem.Cache |
|---|---|---|
| Memory Provider | ❌ | ✅ |
| Cache-Aside | ❌ | ✅ |
| Tag Invalidation | ❌ | ✅ |
| Primary + Fallback Storage | ❌ | ✅ |
| HTTP Response Caching | ❌ | ✅ |
| OpenTelemetry Metrics | ❌ | ✅ |
| Configurable Cache Pipeline | ❌ | ✅ |
Redis and resilience capabilities are provided through their corresponding companion packages and are integrated with the cache pipeline when registered and configured.
🏗 Architecture
Application
│
▼
ICoreCache
│
▼
CachePipeline
│
├── Logging
├── Metrics
├── Fallback (when available)
└── Resilience (when registered)
│
▼
Cache Storage Resolver
│
├── External Storage (Primary)
│
└── Memory Storage (Fallback)
When no external cache storage is registered, Memory is used as the primary storage. When one external storage is registered, it becomes the primary storage and Memory becomes the fallback. The core resolver allows only one external cache storage to be registered.
📚 Documentation
The full documentation includes:
- Getting Started
- Architecture
- Configuration
- Basic Usage
- HTTP Response Caching
- Observability
- Health Checks
- Extensibility
- Roadmap
Visit federin.github.io/CoreSystem.Cache for the complete reference.
🤝 Contributing
Issues, discussions and pull requests are welcome.
📄 License
Released under the MIT License.
| 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 is compatible. 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 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
- CoreSystem.Http (>= 1.2.0)
- CoreSystem.Memory (>= 1.1.0)
- CoreSystem.Resilience (>= 2.1.0)
- CoreSystem.Serialization (>= 1.3.0)
-
net8.0
- CoreSystem.Http (>= 1.2.0)
- CoreSystem.Memory (>= 1.1.0)
- CoreSystem.Resilience (>= 2.1.0)
- CoreSystem.Serialization (>= 1.3.0)
-
net9.0
- CoreSystem.Http (>= 1.2.0)
- CoreSystem.Memory (>= 1.1.0)
- CoreSystem.Resilience (>= 2.1.0)
- CoreSystem.Serialization (>= 1.3.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on CoreSystem.Cache:
| Package | Downloads |
|---|---|
|
CoreSystem.Cache.Rehydration
Cache recovery component for CoreSystem.Cache on .NET 8, .NET 9 and .NET 10 that restores tracked memory fallback entries to the primary cache provider after recovery. |
|
|
CoreSystem.Cache.Redis
Redis external cache provider for CoreSystem.Cache on .NET 8, .NET 9 and .NET 10, with tag-based invalidation, distributed locking, health checks, and optional resilience integration. |
GitHub repositories
This package is not used by any popular GitHub repositories.
3.1.0: Multi-targeting release. The package now ships net8.0, net9.0 and net10.0 assets instead of net8.0 only, so a project on .NET 9 or .NET 10 gets an assembly compiled for its own target framework. The net8.0 asset is unchanged and is still what .NET 8 consumers resolve. Cross-repo dependencies are refreshed to CoreSystem.Http 1.2.0, CoreSystem.Memory 1.1.0, CoreSystem.Resilience 2.1.0 and CoreSystem.Serialization 1.3.0. This is what makes .NET 10 work: earlier Resilience versions constrained Microsoft.Extensions.* to 8.0.x while OpenTelemetry asks for 10.0.0, so a net10.0 consumer failed restore with NU1605. Verified with real net8.0, net9.0 and net10.0 consumer projects: all three restore and resolve with no workaround. The net9.0 and net10.0 assets carry the same code as net8.0. No public API changed, nothing is renamed and no production code changed; the difference is the target frameworks and the declared dependency versions. The three breaking changes from 3.0.0 still apply when migrating from 2.x: CacheOptions.MaxCacheableSize is gone, IExternalCacheStorage replaces ICacheTagIndex<T>, and MemoryKeyTracker and DefaultRequestCachePolicy are no longer public.