IL.InMemoryCacheProvider
2.1.0.1
dotnet add package IL.InMemoryCacheProvider --version 2.1.0.1
NuGet\Install-Package IL.InMemoryCacheProvider -Version 2.1.0.1
<PackageReference Include="IL.InMemoryCacheProvider" Version="2.1.0.1" />
<PackageVersion Include="IL.InMemoryCacheProvider" Version="2.1.0.1" />
<PackageReference Include="IL.InMemoryCacheProvider" />
paket add IL.InMemoryCacheProvider --version 2.1.0.1
#r "nuget: IL.InMemoryCacheProvider, 2.1.0.1"
#:package IL.InMemoryCacheProvider@2.1.0.1
#addin nuget:?package=IL.InMemoryCacheProvider&version=2.1.0.1
#tool nuget:?package=IL.InMemoryCacheProvider&version=2.1.0.1
InMemory Cache Provider
- Basic implementation of generic in-memory cache provider, based on Microsoft.Extensions.Caching.Memory.
- Comes with set of useful thread safe extensions to get objects from cache or add them with factory.
- Introduces several not supported by default methods, like
IEnumerable<string> GetAllKeys()orvoid DeleteAll(). - Supports tags on cache entries and eviction by tag.
Supported frameworks
Targets .NET 10 and 11 only, using the matching major of
Microsoft.Extensions.Caching.Memory. Minimum dependency versions are 10.0.15
and 11.0.0 respectively.
Consumer dependency versions
Runtime dependencies declare these compatibility windows ([ includes the minimum;
) excludes the upper bound):
| Dependency | Target | Allowed versions |
|---|---|---|
Microsoft.Extensions.Caching.Memory |
.NET 10 | [10.0.15, 11.0.0) |
Microsoft.Extensions.Caching.Memory |
.NET 11 | [11.0.0, 12.0.0) |
Concurrency Notes
- Sync and async mutations share one mutation lock; async variants await contention instead of blocking the calling thread.
- Reads are lock-free and may observe transient states during concurrent mutations.
Synchronous and asynchronous factories
Use GetOrAdd(key, Func<T>, ...) for synchronous, in-memory work; it calls the
provider's synchronous Get and Add methods directly under one per-key lock.
For I/O or any task-returning factory, await GetOrAddAsync(key, Func<Task<T>>, ...).
The blocking GetOrAdd(key, Func<Task<T>>, ...) overload has been removed: migrate
those calls to await GetOrAddAsync(...), and make the caller asynchronous.
Do not pass a task-returning factory to the generic synchronous overload, which
would cache the task itself instead of its result. Pure in-memory sync APIs remain available.
Usage sample:
Register in DI with any container of your preference. Microsoft.Extensions.DependencyInjection will be used in this sample.
services.AddSingleton<ICacheProvider, InMemoryCacheProvider>();
class Test(ICacheProvider cacheProvider)
{
async Task FooAsync(Func<Task<string>> valueFactory, CancellationToken cancellationToken = default)
{
var cacheKey = "test";
string[] cacheTags = ["test1", "test2"];
var valueFromCache = await cacheProvider.GetOrAddAsync(cacheKey,
valueFactory,
tags: cacheTags,
cacheCreationCondition: s => !string.IsNullOrEmpty(s),
expirationOptions: new ExpirationOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(1),
AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(10),
SlidingExpiration = TimeSpan.FromSeconds(30)
},
cancellationToken: cancellationToken);
}
}
Nuget
| Product | Versions 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. net11.0 is compatible. |
-
net10.0
- IL.Misc (>= 2.0.0.1)
- Microsoft.Extensions.Caching.Memory (>= 10.0.15 && < 11.0.0)
-
net11.0
- IL.Misc (>= 2.0.0.1)
- Microsoft.Extensions.Caching.Memory (>= 11.0.0 && < 12.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on IL.InMemoryCacheProvider:
| Package | Downloads |
|---|---|
|
IL.RankedCache
Decorator for caching mechanism of your preference allowing to keep track of how many times each entry was accessed, including some manual and automated cleanup possibilities. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.1.0.1 | 85 | 11/18/2026 |
| 2.0.2.2 | 777 | 5/3/2026 |
| 2.0.2.1 | 227 | 3/19/2026 |
| 2.0.1.1 | 161 | 3/19/2026 |
| 2.0.0.2 | 197 | 2/23/2026 |
| 2.0.0.1 | 433 | 1/5/2026 |
| 1.4.0 | 2,059 | 4/8/2025 |
| 1.3.0 | 2,403 | 4/5/2024 |
| 1.2.3 | 297 | 3/30/2024 |
| 1.2.2 | 262 | 3/30/2024 |
| 1.2.1 | 265 | 3/29/2024 |
| 1.2.0 | 381 | 3/28/2024 |
| 1.1.2 | 722 | 3/1/2024 |
| 1.1.1 | 422 | 1/16/2024 |
| 1.1.0 | 408 | 11/7/2023 |
| 1.0.4 | 239 | 11/6/2023 |
| 1.0.1 | 345 | 9/16/2023 |
| 1.0.0 | 293 | 9/15/2023 |