-
Notifications
You must be signed in to change notification settings - Fork 81
Open
Labels
Milestone
Description
A new distributed cache implementation based on Microsoft SQL Server was checked in few days back.
There are two nuget packages related to this:
Microsoft.Framework.Caching.SqlServer
- Has the actual cache implementationMicrosoft.Framework.Caching.SqlConfig
- Has the 'global' command to set up the database table and indexes
Using this cache requires setting up the database and tables that this implementation understands. Follow the steps below for that:
- Create a database in the SQL server manually.
- Run
dnu commands install Microsoft.Framework.Caching.SqlConfig
to install the command calledsqlservercache
- Run
sqlservercache create <connectionstring-to-database> <schema-name> <table-name>
to set up the table and indexes. - Register this cache in DI. Example:
services.AddSqlServerCache(o =>
{
o.ConnectionString = "Server=localhost;Database=CacheSampleDb;Trusted_Connection=True;";
o.SchemaName = "dbo";
o.TableName = "CacheSample";
});
And End-to-end example of using this cache is with Session middleware where session data is stored in database making it available across multiple servers behind a load balancer.
// Registering services
services.AddSqlServerCache(o =>
{
o.ConnectionString = "Server=localhost;Database=CacheSampleDb;Trusted_Connection=True;";
o.SchemaName = "dbo";
o.TableName = "CacheSample";
});
services.AddSession();
// Registering session middleware
app.UseSession();
app.UseMvcWithDefaultRoute();
Code:
- https://github.com/aspnet/Caching/tree/dev/src/Microsoft.Framework.Caching.SqlServer
- https://github.com/aspnet/Caching/tree/dev/src/Microsoft.Framework.Caching.SqlConfig
Samples:
Feedback is welcome