Eryri.FileDistributedCache 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Eryri.FileDistributedCache --version 1.0.1
                    
NuGet\Install-Package Eryri.FileDistributedCache -Version 1.0.1
                    
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="Eryri.FileDistributedCache" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Eryri.FileDistributedCache" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Eryri.FileDistributedCache" />
                    
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 Eryri.FileDistributedCache --version 1.0.1
                    
#r "nuget: Eryri.FileDistributedCache, 1.0.1"
                    
#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 Eryri.FileDistributedCache@1.0.1
                    
#: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=Eryri.FileDistributedCache&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Eryri.FileDistributedCache&version=1.0.1
                    
Install as a Cake Tool

Eryri.Extensions.Caching.FileSystem

A filesystem-backed cache for .NET applications using IDistributedCache / IBufferedDistributedCache.

Designed for low-latency, high-throughput access within a single process, with thread-safe operations and Native AOT compatibility.

Despite implementing IDistributedCache, this is local to one process, not a shared backend.

Features

  • Stores cache payloads on the filesystem.
  • Eviction policies include:
    • Least Recently Used (LRU)
    • Least Frequently Used (LFU)
    • Soonest Time To Live (TTL)
    • First In First Out (FIFO).
  • Supports DistributedCacheEntryOptions options for each entry: AbsoluteExpiration, AbsoluteExpirationRelativeToNow, SlidingExpiration.
  • Supports synchronous and asynchronous cache operations.
  • Auto eviction of expired items.
  • Auto eviction when new items would cause the cache to exceed its size limit.

Installation

dotnet add package Eryri.FileDistributedCache

Quick start

using Eryri.Extensions.Caching.FileSystem;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.DependencyInjection;

// Arrange
using var services = new ServiceCollection()
    .AddDistributedFileCache()
    .BuildServiceProvider();

var cache = services.GetRequiredService<IDistributedCache>();
var key = Guid.NewGuid().ToString("N");
var payload = Guid.NewGuid().ToString("N");

// Act
await cache.SetStringAsync(key, payload);
var actual = await cache.GetStringAsync(key);

// Assert
if (actual != payload)
{
    throw new Exception("FileDistributedCache write value is not the same as the read value");
}
else
{
    Console.WriteLine("FileDistributedCache can write and read");
}

With HybridCache

using Eryri.Extensions.Caching.FileSystem;
using Microsoft.Extensions.Caching.Hybrid;
using Microsoft.Extensions.DependencyInjection;

// Arrange
using var services = new ServiceCollection()
    .AddDistributedFileCache()
    .AddHybridCache().Services
    .BuildServiceProvider();

var cache = services.GetRequiredService<HybridCache>();
var key = Guid.NewGuid().ToString("N");
var payload = Guid.NewGuid().ToString("N");
var options = new HybridCacheEntryOptions
{
    Flags = HybridCacheEntryFlags.DisableLocalCache
};

// Act
await cache.SetAsync(key, payload, options);
var actual = await cache.GetOrCreateAsync(key, _ => ValueTask.FromResult(string.Empty), options);

// Assert
if (actual != payload)
{
    throw new Exception("FileDistributedCache write value is not the same as the read value");
}
else
{
    Console.WriteLine("FileDistributedCache can write and read");
}

Configuration

Option Purpose
[ExpirationScanFrequency] Minimum length of time between removing expired items. Zero or negative will result in the next execution being scheduled for the next shortest TTL.
[EvictionPolicy] Eviction policy used when reducing the number of cached files beyond already expired items..
[SizeLimitGiB] Maximum size of the cache in GiB.
[SizeLimitMiB] Maximum size of the cache in MiB.
[SizeLimitBytes] Maximum size of the cache in bytes.

Expiration and eviction

  • Expiration: A background timer removes expired entries. It is scheduled for the next entry due to expire.
  • Size limits: When an added entry would exceed the configured limit, the cache removes entries according to the eviction policy to make room.
  • Manual compaction: When no size limit is configured, call IFileDistributedCache.Compact(double percentage) to remove at least the specified fraction of entries. For example, 0.10 removes at least 10%, selected according to the eviction policy.
  • Write failures: If the filesystem rejects a write, the entry is not added to the cache.
  • Storage location: Cache files are stored in a temporary directory under the current user’s temp folder and removed during normal application shutdown.

Operational notes

  • Durability: Treat cached entries as disposable. The application must be able to recreate data after a restart or cache miss.
  • Permissions: The application identity needs permission to create, read, write, and delete files in its temporary directory.
  • Cleanup: Cache files are removed during normal shutdown. An abrupt exit may leave files behind; [document how these are found or cleaned up].
  • Filesystem failures: Failed file creation, returns without caching, and logs an error with the underlying filesystem error.]
Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 66 10/3/2026
1.0.4 71 10/2/2026
1.0.3 76 9/30/2026
1.0.2 70 9/29/2026
1.0.1 79 9/28/2026
1.0.0 75 9/28/2026