First, create the cache table by running:
dotnet sql-cache create "Data Source=MyServer;Initial Catalog=MyDb;Integrated Security=True;" dbo MyTable
Install with nuget: Microsoft.Extensions.Caching.SqlServer
Register the service in the DI
builder.Services.AddDistributedSqlServerCache(options =>
{
options.ConnectionString = builder.Configuration.GetConnectionString(
"DefaultConnection");
options.SchemaName = "dbo";
options.TableName = "MyTable";
});
Inject the IDistributedCache instance