Skip to content

Caching with MySQL

Peter Chapman edited this page Jan 20, 2023 · 4 revisions

The GoTo.Bible application supports caching of provider API calls using Microsoft SQL Server, MariaDB, MySQL, or In-Memory Caching.

Table Structure

CREATE TABLE IF NOT EXISTS `Cache` (
	`Id` varchar(449) CHARACTER SET ascii COLLATE ascii_bin NOT NULL,
	`AbsoluteExpiration` datetime(6) DEFAULT NULL,
	`ExpiresAtTime` datetime(6) NOT NULL,
	`SlidingExpirationInSeconds` bigint(20) DEFAULT NULL,
	`Value` longblob NOT NULL,
	PRIMARY KEY(`Id`),
	KEY `Index_ExpiresAtTime` (`ExpiresAtTime`)
);

User Secret Configuration

The following configuration can be using with MySQL, assuming you have already created a database called GoToBible:

dotnet user-secrets set "Providers:Cache:DatabaseProvider" "mysql"
dotnet user-secrets set "Providers:Cache:ConnectionString" "Server=localhost;Database=GoToBible;User=root;Password=;Allow User Variables=true;"
dotnet user-secrets set "Providers:Cache:SchemaName" "GoToBible"
dotnet user-secrets set "Providers:Cache:TableName" "Cache"

The following configuration can be using with MariaDB, assuming you have already created a database called GoToBible:

dotnet user-secrets set "Providers:Cache:DatabaseProvider" "mariadb"
dotnet user-secrets set "Providers:Cache:ConnectionString" "Server=localhost;Database=GoToBible;User=root;Password=;Allow User Variables=true;"
dotnet user-secrets set "Providers:Cache:SchemaName" "GoToBible"
dotnet user-secrets set "Providers:Cache:TableName" "Cache"

The following configuration can be using with MySQL if you are running a specific version of MySQL:

dotnet user-secrets set "Providers:Cache:DatabaseProvider" "mysql"
dotnet user-secrets set "Providers:Cache:DatabaseVersion" "8.0.31"
dotnet user-secrets set "Providers:Cache:ConnectionString" "Server=localhost;Database=GoToBible;User=root;Password=;Allow User Variables=true;"
dotnet user-secrets set "Providers:Cache:SchemaName" "GoToBible"
dotnet user-secrets set "Providers:Cache:TableName" "Cache"

Notes

  • Your connection string must contain Allow User Variables=true.