LightCache 1.0.2

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

LightCache

A memory cache that evicts based on LRU, time, and size.

LightCache is a lightweight, thread-safe in-memory cache for .NET that supports:<br>

Least Recently Used (LRU) eviction<br> Absolute and sliding expiration<br> Size-based eviction<br> Background cleanup<br> Bulk insert support for high-performance scenarios

Features<br> Thread-safe using internal locking<br> LRU eviction via linked list tracking<br> Configurable size limits to prevent memory overuse<br> Expiration support<br> Absolute expiration<br> Sliding expiration<br> Bulk operations to reduce lock contention<br> Background cleanup using a timer

Installation To install, clone the repository

git clone https://github.com/janzenhouchenwilder/QuickCache.git

To use<br> var cache = new LightCache<string, string>(10000);<br> or for dependency injection<br> services.AddSingleton<ILightCache<string, string>, LightCache<int, int>>();<br> If you want to set the size of the cache<br>

builder.Services.AddSingleton<ILightCache<int, Person>>(options =>
{
    return new LightCache<int, Person>(50000, 20000);
});

Add or update an item<br> cache.Put("key", "value", new LightCacheEntryOptions { Size = 1, AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10) });

Retrieve an item<br> if (cache.TryGet("key", out var value)) { Console.WriteLine(value); }

Remove an item<br> if (cache.TryGet("key", out var value)) { Console.WriteLine(value); }

Insert multiple items (Large inserts)<br> cache.PutMany(items);

Performance Notes<br> Use PutMany for bulk inserts to avoid lock contention.<br> Designed for high-throughput with minimal allocations.

Benchmark Dotnet for LightCache Put(TKey key, TValue, LightCacheEntryOptions? options) method.<br> | Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | |------- |---------:|----------:|----------:|---------:|---------:|----------:| | Put | 3.802 ms | 0.0753 ms | 0.1451 ms | 578.1250 | 570.3125 | 3.48 MB |

Run time: 00:00:33 (33.73 sec), executed benchmarks: 1

Benchmark Dotnet for MemoryCache Set(object key, TItem value, MemoryCacheEntryOptions? options) method.<br> | Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated | |------- |---------:|----------:|----------:|---------:|---------:|----------:| | Set | 4.530 ms | 0.0906 ms | 0.2449 ms | 695.3125 | 687.5000 | 4.17 MB |

Run time: 00:01:00 (60.23 sec), executed benchmarks: 1

Benchmark Dotnet for LightCache TryGet(TKey key, out TValue value) method.<br> | Method | Mean | Error | StdDev | Allocated | |------- |---------:|----------:|----------:|----------:| | TryGet | 1.274 ms | 0.0250 ms | 0.0470 ms | 40 B |

Run time: 00:00:41 (41.65 sec), executed benchmarks: 1

Benchmark Dotnet for MemoryCache TryGetValue(object key, out TItem value) method.<br> | Method | Mean | Error | StdDev | Gen0 | Allocated | |------- |---------:|---------:|---------:|--------:|----------:| | TryGet | 821.1 us | 16.18 us | 34.12 us | 69.3359 | 427.38 KB |

Run time: 00:00:57 (57.74 sec), executed benchmarks: 1

These tests were conducted by querying a database with 18000 rows of data and adding/retrieving from the cache.

Limitations<br> In-memory only, not distributed<br> Global lock may cause contention under extreme parallel locks

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.
  • net8.0

    • No dependencies.

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 89 5/3/2026
1.0.4 98 4/27/2026
1.0.3 103 4/20/2026
1.0.2 99 4/18/2026
1.0.1 87 4/18/2026
1.0.0 94 4/18/2026