Skip to content

Libraries for in-memory caching and distributed caching using MySql.

License

Notifications You must be signed in to change notification settings

ChaosEngine/Caching-MySQL

 
 

Repository files navigation

Caching-MySQL

AppVeyor build status NuGet

Basing on https://learn.microsoft.com/en-us/aspnet/core/performance/caching/distributed and modified accordingly:

Distributed MySQL Server Cache

The Distributed MySQL Server Cache implementation (AddDistributedMySqlCache) allows the distributed cache to use a MySQL Server database as its backing store. To create a MySQL Server cached item table in a MySQL Server instance, you can use the dotnet-mysql-cache tool. The tool creates a table with the name and schema that you specify.

Create a table in MySQL Server by running the dotnet mysql-cache create command. Provide the MySQL Server connection string, instance (for example server=192.169.0.1), database (for example, databaseName), and table name (for example, NewTableName):

dotnet mysql-cache create "server=192.169.0.1;user id=userName;password=P4ssword123!;port=3306;database=databaseName;Allow User Variables=True" databaseName "NewTableName"

A message is logged to indicate that the tool was successful:

Table and index were created successfully.

The table created by the dotnet-mysql-cache tool has the following schema:

MySQL Server Cache Table

Note

An app should manipulate cache values using an instance of IDistributedCache, not any other.

The example snippet how to implement MySql Server cache in Program.cs:

builder.Services.AddDistributedMySqlCache(options =>
{
    options.ConnectionString = builder.Configuration.GetConnectionString("DistCache_ConnectionString");
    options.SchemaName = "databaseName";
    options.TableName = "NewTableName";
});

Note

A ConnectionString (and optionally, SchemaName and TableName) are typically stored outside of source control (for example, stored by the Secret Manager or in appsettings.json/appsettings.{Environment}.json files). The connection string may contain credentials that should be kept out of source control systems.

Use the distributed cache

One can use same technique as described in this section Use the distributed cache

About

Libraries for in-memory caching and distributed caching using MySql.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.8%
  • Other 0.2%