EasyMemoryCache 3.1.7
dotnet add package EasyMemoryCache --version 3.1.7
NuGet\Install-Package EasyMemoryCache -Version 3.1.7
<PackageReference Include="EasyMemoryCache" Version="3.1.7" />
<PackageVersion Include="EasyMemoryCache" Version="3.1.7" />
<PackageReference Include="EasyMemoryCache" />
paket add EasyMemoryCache --version 3.1.7
#r "nuget: EasyMemoryCache, 3.1.7"
#:package EasyMemoryCache@3.1.7
#addin nuget:?package=EasyMemoryCache&version=3.1.7
#tool nuget:?package=EasyMemoryCache&version=3.1.7
EasyMemoryCache
One ICaching interface for in-memory cache, Redis, and Memcached. Sync and async, with dependency injection for .NET 8, 9, and 10.
Install
dotnet add package EasyMemoryCache
Quick start
builder.Services.AddEasyCache(new CacheSettings
{
CacheProvider = CacheProvider.MemoryCache
});
public class UserService
{
private readonly ICaching _caching;
public UserService(ICaching caching) => _caching = caching;
public Task<List<User>> GetUsersAsync() =>
_caching.GetOrSetObjectFromCacheAsync("users", 20, LoadUsersAsync);
}
The factory runs only on a cache miss. Full samples are in the repository.
Providers
In-memory
"CacheSettings": {
"CacheProvider": "MemoryCache"
}
Redis
RedisSerialization accepts Newtonsoft (the default) or Protobuf.
builder.Services.AddEasyCache(new CacheSettings
{
CacheProvider = CacheProvider.Redis,
RedisConnectionString = "localhost:6379,abortConnect=False",
RedisSerialization = SerializationType.Protobuf
});
Memcached
Pass the configuration section so server and socket-pool settings are bound.
builder.Services.AddEasyCache(
builder.Configuration.GetSection("CacheSettings").Get<CacheSettings>(),
builder.Configuration.GetSection("CacheSettings"));
"CacheSettings": {
"CacheProvider": "Memcached",
"Servers": [
{ "Address": "localhost", "Port": 11211 }
]
}
Usage
var names = await _caching.GetOrSetObjectFromCacheAsync("names", 20, LoadNamesAsync);
var namesForTenant = await _caching.GetOrSetObjectFromCacheAsync(
"names",
20,
() => LoadNamesAsync(tenantId));
Empty collections are not stored unless you opt in with cacheEmptyList: true. The default interval is minutes.
var snapshot = await _caching.GetOrSetObjectFromCacheAsync(
"snapshot",
cacheTime: 30,
objectSettingFunction: LoadSnapshotAsync,
cacheEmptyList: true,
interval: CacheTimeInterval.Seconds);
_caching.SetValueToCache("token", token, cacheTime: 2, interval: CacheTimeInterval.Hours);
var token = _caching.GetValueFromCache<string>("token");
_caching.Invalidate("users");
await _caching.InvalidateAllAsync();
License
| 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 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. |
-
net10.0
- AsyncKeyedLock (>= 8.1.2)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Caching.Memory (>= 10.0.13)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 10.0.13)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Options (>= 10.0.13)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.13)
- Microsoft.NETCore.Platforms (>= 7.0.4)
- Newtonsoft.Json (>= 13.0.4)
- Newtonsoft.Json.Bson (>= 1.0.3)
- protobuf-net (>= 3.4.30)
-
net8.0
- AsyncKeyedLock (>= 8.1.2)
- Backport.System.Threading.Lock (>= 3.1.8)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Caching.Memory (>= 10.0.13)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 10.0.13)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Options (>= 10.0.13)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.13)
- Microsoft.NETCore.Platforms (>= 7.0.4)
- Newtonsoft.Json (>= 13.0.4)
- Newtonsoft.Json.Bson (>= 1.0.3)
- protobuf-net (>= 3.4.30)
-
net9.0
- AsyncKeyedLock (>= 8.1.2)
- Microsoft.Extensions.Caching.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Caching.Memory (>= 10.0.13)
- Microsoft.Extensions.Caching.StackExchangeRedis (>= 10.0.13)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.13)
- Microsoft.Extensions.Options (>= 10.0.13)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.13)
- Microsoft.NETCore.Platforms (>= 7.0.4)
- Newtonsoft.Json (>= 13.0.4)
- Newtonsoft.Json.Bson (>= 1.0.3)
- protobuf-net (>= 3.4.30)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on EasyMemoryCache:
| Package | Downloads |
|---|---|
|
AlertHawk.Monitoring.Domain
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.1.7 | 70 | 10/18/2026 |
| 3.1.6 | 522 | 10/1/2026 |
| 3.1.5 | 110 | 9/27/2026 |
| 3.1.4 | 321 | 8/13/2026 |
| 3.1.3 | 470 | 5/29/2026 |
| 3.1.2 | 265 | 5/1/2026 |
| 3.1.1 | 214 | 4/4/2026 |
| 3.0.7 | 254 | 3/21/2026 |
| 3.0.6 | 1,433 | 1/21/2026 |
| 3.0.5 | 2,453 | 11/13/2025 |
| 3.0.4 | 5,553 | 6/5/2025 |
| 3.0.3 | 694 | 4/22/2025 |
| 3.0.2 | 3,882 | 12/21/2024 |
| 3.0.1 | 460 | 12/3/2024 |
| 3.0.0 | 831 | 11/19/2024 |
| 2.0.9 | 1,831 | 10/13/2024 |
| 2.0.8 | 1,860 | 9/13/2024 |
| 2.0.7 | 1,517 | 8/21/2024 |
| 2.0.6 | 380 | 8/12/2024 |
| 2.0.5 | 730 | 7/30/2024 |
.NET 10 support