Common interface to manage cache using different providers.
$ dotnet add package microservice.toolkit.cachemanagerThe library is a work in progress. It is not yet considered production-ready.
Common interface to manage cache using different providers.
Install-Package microservice.toolkit.cachemanager -Version 0.9.1
dotnet add package microservice.toolkit.cachemanager --version 0.9.1
<PackageReference Include="microservice.toolkit.cachemanager" Version="0.9.1" />
Task<bool> Set(string key, string value, long issuedAt);
Adds an entry in the cache provider with an expiration time (UTC Unix timestamp in milliseconds).
// 2 days until expiration time
var issuedAt = DateTimeOffset.UtcNow.AddDays(2).ToUnixTimeMilliseconds()
Task<bool> Set(string key, string value);
Adds an entry in the cache provider without an expiration time.
Task<string> Get(string key);Tries to retrieve the value of the entry using the key. If the entry does not exist or is expired the method returns null.
Task<bool> Delete(string key);Removed the entry from the cache provider.
<a name="sqlite"></a> To start using SQLite cache manager, first install the required package:
<PackageReference Include="Microsoft.Data.SQLite" Version="5.0.10" />and create the table cache:
CREATE TABLE cache(
id TEXT PRIMARY KEY,
value TEXT NOT NULL,
issuedAt INTEGER NOT NULL
);<a name="mysql"></a> To start using MySql cache manager, first install the required package:
<PackageReference Include="MySqlConnector" Version="1.3.12" />and create the table cache:
CREATE TABLE cache(
id VARCHAR(256) PRIMARY KEY,
value TEXT NOT NULL,
issuedAt BIGINT NOT NULL
);<a name="memcached"></a> To start using Memcached cache manager, first install the required package:
<PackageReference Include="Enyim.Memcached2" Version="0.6.8" />How to use:
var manager = new MemcachedCacheManager("localhost:11211");Or, if you are using a cluster:
var manager = new MemcachedCacheManager("localhost:11211,localhost:11212");<a name="redis"></a> To start using Redis cache manager, first install the required package:
<PackageReference Include="StackExchange.Redis" Version="2.2.62" />How to use:
var manager = new RedisCacheManager("localhost:6379");