ScaledDomains.Extensions.Caching.MySql is a free, open source distributed cache implementation using MySql as datastore, inspired by Microsoft.Extensions.Cachning.SqlServer. Founded and maintained by Endre Toth and Attila Ersek.
The Distributed MySQL Server Cache implementation allows the distributed cache to use a MySQL Server database as its caching store. To create a table in a database instance, you can use the mysql-distributed-cache
tool. The tool creates a table the name that you specify.
mysql-distributed-cache
.NET CLI Tool
The following example creates table with myDistributedCache
name on MySQL server (example.com
) under the pizzaordersystem-db
schema.
The CLI tool parameters:
- [connectionString] - The mysql connection string to connect to the database.
- [tableName] - Name of the table to be created.
mysql-distributed-cache Server=example.com;Database=pizzaordersystem-db;User=dbAdmin; myDistributedCache
The connection string may contain credentials that should be kept out of source control systems.
The table has the following schema:
describe `pizzaordersystem-db`.`myDistributedCache`;
Field | Type | Null | Key | Default | Extra |
---|---|---|---|---|---|
Id | varchar(767) | NO | PRI | NULL | |
AbsoluteExpiration | datetime(6) | YES | NULL | ||
ExpiresAt | datetime(6) | NO | MUL | NULL | |
SlidingExpiration | time(6) | YES | NULL | ||
Value | longblob | NO | NULL |
The package manipulates cache values using an instance of IDistributedCache.
services.AddDistributedMySqlServerCache(options => {
options.ConnectionString = _config["DistributedCache_ConnectionString"];
options.TableName = "myDistributedCache";
});
Property | Type | Description | Default | Required/Optional |
---|---|---|---|---|
ConnectionString |
string | The connection string to the database. | REQUIRED | |
TableName |
string | Name of the table where the cache items are stored. | REQUIRED | |
ExpirationScanFrequency |
TimeSpan | The minimum length of time between successive scans for expired items. | 00:20:00 | OPTIONAL |
The IDistributedCache interface provides basic methods to manage items, in the distributed cache implementation:
- Get, GetAsync: Accepts a string key and retrieves a cached item as a
byte[]
array if found in the cache. - Set, SetAsync: Adds an item (as
byte[]
array) to the cache using a string key. - Refresh, RefreshAsync: Refreshes an item in the cache based on its key, resetting its sliding expiration timeout (if any).
- Remove, RemoveAsync: Removes a cache item based on its string key.
- Cache key length must be less than 767 and encoding should be ASCII.
- The maximum size of the cache item is 4Gb.
Please use the Issue Tracker.