In-memory caching abstraction with lazy task caching support for async operations. Features configurable expiration modes (sliding/absolute), thread-safe operations, and optimized for caching expensive computations and external API calls.
License
—
Deps
5
Install Size
—
Vulns
✓ 0
Published
Dec 10, 2025
$ dotnet add package SolTechnology.Core.CacheThe SolTechnology.Core.Cache library provides functionality needed for task caching. It handles needed services registration and configuration. It relies on IMemoryCache. The use case is to cache parts of the code which are time consuming and the result does not change. Ex: external http calls for non-changing data.
For installing the library, reference SolTechnology.Core.Cache nuget package and invoke AddCache() service collection extension method:
services.AddCache();
"Configuration": {
"CacheConfiguration": {
"ExpirationMode": "Absolute or Sliding",
"ExpirationSeconds": 300
}
}
var cacheConfiguration = new CacheConfiguration
{
ExpirationMode = "Absolute",
ExpirationSeconds= 300
};
builder.Services.AddCache(cacheConfiguration);
public SyncPlayer(
IFootballDataApiClient footballDataApiClient,
IPlayerRepository playerRepository,
IApiFootballApiClient apiFootballApiClient,
ILazyTaskCache lazyTaskCache)
{
_footballDataApiClient = footballDataApiClient;
_playerRepository = playerRepository;
_apiFootballApiClient = apiFootballApiClient;
_lazyTaskCache = lazyTaskCache;
}
var clientPlayer = await _lazyTaskCache.GetOrAdd(playerIdMap.FootballDataId, _footballDataApiClient.GetPlayerById);