SolTechnology.Core.Cache
0.2.1
dotnet add package SolTechnology.Core.Cache --version 0.2.1
NuGet\Install-Package SolTechnology.Core.Cache -Version 0.2.1
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="SolTechnology.Core.Cache" Version="0.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SolTechnology.Core.Cache --version 0.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SolTechnology.Core.Cache, 0.2.1"
#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.
// Install SolTechnology.Core.Cache as a Cake Addin #addin nuget:?package=SolTechnology.Core.Cache&version=0.2.1 // Install SolTechnology.Core.Cache as a Cake Tool #tool nuget:?package=SolTechnology.Core.Cache&version=0.2.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Overview
The 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.
Registration
For installing the library, reference SolTechnology.Core.Cache nuget package and invoke AddCache() service collection extension method:
services.AddCache();
Configuration
- The first option is to create an appsettings.json section:
"Configuration": {
"CacheConfiguration": {
"ExpirationMode": "Absolute or Sliding",
"ExpirationSeconds": 300
}
}
- Alternatevely the same settings can be provided by optional parameter during registration:
var cacheConfiguration = new CacheConfiguration
{
ExpirationMode = "Absolute",
ExpirationSeconds= 300
};
builder.Services.AddCache(cacheConfiguration);
- If not provided, the default configuration will be applied, which is Sliding ExpirationMode and 300 seconds expiration time. That means if the cache was not hit in 5 mins, it will be cleared.
Usage
- Inject ILazyTaskCache into your service
public SyncPlayer(
IFootballDataApiClient footballDataApiClient,
IPlayerRepository playerRepository,
IApiFootballApiClient apiFootballApiClient,
ILazyTaskCache lazyTaskCache)
{
_footballDataApiClient = footballDataApiClient;
_playerRepository = playerRepository;
_apiFootballApiClient = apiFootballApiClient;
_lazyTaskCache = lazyTaskCache;
}
- Cache repeatable operation and it's key
var clientPlayer = await _lazyTaskCache.GetOrAdd(playerIdMap.FootballDataId, _footballDataApiClient.GetPlayerById);
- The key is supposed to be a complex object (ex: command or query), to avoid returning incorrect cache item
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.0
- Microsoft.Extensions.Caching.Memory (>= 7.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 7.0.2)
- Microsoft.Extensions.DependencyInjection (>= 6.0.0)
- Microsoft.Extensions.Options (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.