Search code examples
c#sql-serverdistributed-caching

Can I use In-Memory Engine for SQL Server Distributed Cache in ASP.NET Core?


I’m currently using a Distributed SQL Server Cache in ASP.NET Core.

The Distributed SQL Server Cache implementation (AddDistributedSqlServerCache) allows the distributed cache to use a SQL Server database as its backing store.

For documentation click here

I used the following method:

services.AddDistributedSqlServerCache(options =>
{
    options.ConnectionString = 
        _config["DistCache_ConnectionString"];
    options.SchemaName = "dbo";
    options.TableName = "MyDiskBasedTable";
});

Can I create database objects using AddDostributedSqlServerCache implementation in order to use In-Memory Engine (In-Memory Tables, Natively Compiled Stored Procedures, memory-optimized table type) for best performances?


Solution

  • The table that is created by dotnet sql-cache create has a clusterd primary key and uses datetimeoffset both of them are not supported when creating in-memory OLTP tables.

    Although there is a PR for this in the repository.

    You could use his fork, although saving datetimeoffest as varchar is not the recommend way.