CoreSystem.Cache.Rehydration 2.0.0

dotnet add package CoreSystem.Cache.Rehydration --version 2.0.0
                    
NuGet\Install-Package CoreSystem.Cache.Rehydration -Version 2.0.0
                    
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="CoreSystem.Cache.Rehydration" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CoreSystem.Cache.Rehydration" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="CoreSystem.Cache.Rehydration" />
                    
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 CoreSystem.Cache.Rehydration --version 2.0.0
                    
#r "nuget: CoreSystem.Cache.Rehydration, 2.0.0"
                    
#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 CoreSystem.Cache.Rehydration@2.0.0
                    
#: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=CoreSystem.Cache.Rehydration&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CoreSystem.Cache.Rehydration&version=2.0.0
                    
Install as a Cake Tool

πŸ”„ CoreSystem.Cache.Rehydration

Cache recovery component for CoreSystem.Cache on .NET 8

NuGet Downloads License .NET

CoreSystem.Cache.Rehydration is an optional recovery component for CoreSystem.Cache. It restores entries that were kept in the memory fallback after the primary cache provider becomes healthy again.

The package does not implement a cache provider. It reads tracked entries from the memory fallback and writes them to the current primary storage.


πŸ“¦ CoreSystem Ecosystem

Package Responsibility
CoreSystem.Cache Cache orchestration, storage resolution and fallback support
CoreSystem.Cache.Rehydration Recovery of tracked fallback entries into the primary storage

CoreSystem.Cache.Rehydration depends on the abstractions and services provided by CoreSystem.Cache.

An external primary cache storage implementing IExternalCacheStorage must be registered before rehydration is enabled.


πŸš€ Getting Started

Register CoreSystem.Cache and an external primary cache provider first.

services.AddCoreCache(options =>
{
    options.InstanceName = "my-app:";
});

services.AddCoreCacheRedis(options =>
{
    options.Configuration = redis =>
    {
        redis.EndPoints.Add("localhost", 6379);
    };
});

Then register rehydration:

services.AddCoreCacheRehydration(options =>
{
    options.Enabled = true;
    options.Interval = TimeSpan.FromSeconds(30);
});

Rehydration registration requires:

  • an enabled Core.Cache registration;
  • an IExternalCacheStorage registration.

If the core cache is disabled, the rehydration services are not registered. If the primary storage is not registered, registration throws an InvalidOperationException.


πŸ”„ How Recovery Works

The recovery process is driven by entries marked by the core cache with:

CacheEntryOptions.Rehydrate

The memory fallback tracks those entries. During a rehydration cycle:

Memory fallback
      β”‚
      β–Ό
Tracked cache keys
      β”‚
      β–Ό
MemoryRehydrationSource
      β”‚
      β–Ό
CacheRehydrator
      β”‚
      β–Ό
PrimaryRehydrationTarget
      β”‚
      β–Ό
ICacheStorageResolver.Primary

An entry contains its key and value and can also contain its remaining expiration and tags.

The primary storage receives the remaining expiration and tags when they are available.


❀️ Primary Recovery Detection

Rehydration is not executed simply because the primary is currently healthy.

RehydrationService checks health checks tagged:

primary

A recovery is detected only after the service has observed the primary as unhealthy and subsequently observes it as healthy.

If no health check tagged primary exists, rehydration is not triggered.

After a successful recovery cycle, the component does not repeatedly rehydrate while the primary remains healthy. A new rehydration requires another unhealthy-to-healthy transition.


βš™οΈ Configuration

RehydrationOptions exposes the following settings:

Option Default Description
Enabled true Enables registration of the rehydration services
Interval 30 seconds Delay used by the background rehydration service

Example:

services.AddCoreCacheRehydration(options =>
{
    options.Enabled = true;
    options.Interval = TimeSpan.FromSeconds(30);
});

When Enabled is false, the options instance remains registered but the rehydration source, target, rehydrator, service and hosted background service are not registered.


🧠 Rehydration Behavior

The rehydration component processes tracked entries independently.

When an entry is successfully stored in the primary provider, it is removed from the memory fallback.

If storing an entry fails:

  • the failure is logged;
  • the entry is not removed from the fallback;
  • processing continues with the next entry;
  • the entry remains available for a later rehydration cycle.

Expired or unavailable memory entries are ignored by the rehydration source.


🧩 Extensibility

The implementation separates the recovery source from the recovery target:

  • IRehydrationSource obtains recoverable entries.
  • IRehydrationTarget stores entries in the primary cache.
  • ICacheRehydrator coordinates the transfer.

The current source and target abstractions are internal implementation boundaries. The package does not currently expose a public provider SDK for replacing the rehydration source or target.


πŸ§ͺ Tests

The available unit tests cover:

  • rehydration entry creation and optional properties;
  • registration requirements;
  • disabled-cache and disabled-rehydration behavior;
  • primary storage requirements;
  • memory entry tracking and extraction;
  • expiration and tag preservation;
  • expired-entry handling;
  • storage into the primary provider;
  • removal after successful storage;
  • retention after storage failures;
  • continuation after an individual entry failure;
  • primary unhealthy-to-healthy recovery detection;
  • background cycle execution and cancellation.

πŸ“š Documentation


πŸ—ΊοΈ Roadmap

The current implementation focuses on reliable recovery of tracked memory fallback entries.

Potential future improvements include additional diagnostics, configurable batch processing and additional recovery policies.


πŸ“„ License

MIT

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 (1)

Showing the top 1 NuGet packages that depend on CoreSystem.Cache.Rehydration:

Package Downloads
CoreSystem.Cache.Redis

Redis external cache provider for CoreSystem.Cache on .NET 8, with tag-based invalidation, distributed locking, health checks, and optional resilience integration.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 95 8/16/2026