LightCache 1.0.2
See the version list below for details.
dotnet add package LightCache --version 1.0.2
NuGet\Install-Package LightCache -Version 1.0.2
<PackageReference Include="LightCache" Version="1.0.2" />
<PackageVersion Include="LightCache" Version="1.0.2" />
<PackageReference Include="LightCache" />
paket add LightCache --version 1.0.2
#r "nuget: LightCache, 1.0.2"
#:package LightCache@1.0.2
#addin nuget:?package=LightCache&version=1.0.2
#tool nuget:?package=LightCache&version=1.0.2
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 | 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 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. |
-
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.