DragonHoard.InMemory 2.4.5

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

DragonHoard

.NET Publish License: Apache-2.0

DragonHoard is a .NET in-memory caching library with a small API for storing, retrieving, expiring, and grouping cached values. Choose its lightweight in-memory provider or a provider backed by Microsoft.Extensions.Caching.Memory.

Why DragonHoard?

  • Register caches through Microsoft.Extensions.DependencyInjection.
  • Create named caches for separate workloads.
  • Set absolute or sliding expiration, priority, size, and tags per entry.
  • Retrieve or remove entries by key or tag, and compact a cache when needed.
  • Target .NET 8, .NET 9, and .NET 10.

DragonHoard is an in-process cache. It does not persist entries or synchronize them between application instances.

Choose a provider

Install one provider package for your application. Both include the core API as a dependency.

Provider NuGet package Use when
DragonHoard in-memory DragonHoard.InMemory You want DragonHoard's built-in in-memory cache.
Microsoft memory cache DragonHoard.Microsoft.Extensions.Caching.Memory You want DragonHoard's API backed by Microsoft.Extensions.Caching.Memory.

Install

Install the provider you chose with the .NET CLI:

dotnet add package DragonHoard.InMemory

Or install the Microsoft memory cache provider:

dotnet add package DragonHoard.Microsoft.Extensions.Caching.Memory

Quick start

This example registers the in-memory provider, creates the default cache, and stores and retrieves a value. Replace AddInMemoryHoard() with AddMemoryCacheHoard() to use the Microsoft memory cache provider.

using DragonHoard.Core;
using DragonHoard.Core.Interfaces;
using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();
services.AddInMemoryHoard();

using var serviceProvider = services.BuildServiceProvider();
var cacheManager = serviceProvider.GetRequiredService<Cache>();
var cache = cacheManager.GetOrAddCache()!;

cache.Set("greeting", "Hello, cache!");
if (cache.TryGetValue<string>("greeting", out var greeting))
{
    Console.WriteLine(greeting);
}

The Cache manager is registered as a singleton. It provides access to the default cache and additional named caches. Resolve it through dependency injection rather than creating a new manager for each operation.

Common operations

Create a named cache

Use a descriptive name to keep unrelated data in separate caches:

ICache productCache = cacheManager.GetOrAddCache("products")!;

Set expiration and tags

cache.Set("product:42", product, new CacheEntryOptions
{
    AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10),
    Tags = ["products", "featured"]
});

Entries can also use AbsoluteExpiration, SlidingExpiration, Priority, and Size options. The in-memory provider supports capacity and scan-frequency configuration through AddInMemoryHoard:

services.AddInMemoryHoard(options =>
{
    options.MaxCacheSize = 10_000;
    options.ScanFrequency = TimeSpan.FromMinutes(2);
});

Remove or retrieve entries

cache.Remove("product:42");
bool found = cache.TryGetValue<Product>("product:42", out var product);

cache.RemoveByTag("featured");
Product[] featuredProducts = cache.GetByTag<Product>("featured");

Compact a cache

Compact removes a fraction of entries according to the provider's eviction policy. For DragonHoard's in-memory provider, expired entries are removed first; remaining entries are considered from lowest to highest priority, then by expiration and last-access time.

cache.Compact(0.25); // Ask the provider to remove about 25% of its entries.

Expiration and provider behavior

Expiration and eviction details depend on the provider. The in-memory provider uses a one-minute scan frequency by default. Expired values should not be treated as available after expiration, but background cleanup timing can depend on cache activity. Compact also follows the selected provider's eviction policy.

Develop and test

The repository contains the library, an example application, tests, and BenchmarkDotNet benchmarks. A .NET 10 SDK is needed to build and test the full solution; the library packages target .NET 8, .NET 9, and .NET 10.

git clone https://github.com/JaCraig/DragonHoard.git
cd DragonHoard
dotnet build DragonHoard.sln
dotnet test DragonHoard.sln

Run the example or benchmarks with:

dotnet run --project DragonHoard.Example
dotnet run -c Release --project DragonHoard.Benchmarks

Benchmark results depend on the machine, runtime, and workload. Run the benchmarks yourself to compare current results rather than relying on historical numbers.

Documentation and help

License

DragonHoard is licensed under the Apache License 2.0.

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

NuGet packages (2)

Showing the top 2 NuGet packages that depend on DragonHoard.InMemory:

Package Downloads
Inflatable

Inflatable is a simple ORM.

sundial.core

Sundial is a profiler library used for both comparison of multiple bits of code and hot spot detection.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.4.5 64 11/3/2026
2.3.24 709 7/16/2026
2.3.23 293 6/10/2026
2.3.22 152 6/10/2026
2.3.21 178 5/27/2026
2.3.20 418 5/14/2026
2.3.19 149 5/13/2026
2.3.18 344 4/27/2026
2.3.17 220 4/24/2026
2.3.16 181 4/23/2026
2.3.15 165 4/22/2026
2.3.14 144 4/22/2026
2.3.13 301 4/16/2026
2.3.12 155 4/15/2026
2.3.11 152 4/15/2026
2.3.10 360 3/30/2026
2.3.9 167 3/29/2026
2.3.8 449 3/16/2026
2.3.7 237 3/13/2026
2.3.6 276 3/12/2026
Loading failed