liveBook · Manning

Microsoft.Extensions.Caching.SqlServer

As explained in Building Web APIs with ASP.NET Core

Microsoft.Extensions.Caching.SqlServer is a .NET library package that provides an IDistributedCache implementation backed by SQL Server.

Microsoft.Extensions.Caching.SqlServer is a .NET package that provides an IDistributedCache implementation backed by SQL Server. Configure it in Program.cs with an existing connection string, schema, and dedicated AppCache table. section 8.4.2

Listing 8.7 Program.cs file: Distributed SQL Server cache service
builder.Services.AddDistributedSqlServerCache(options =>                  #1
{
    options.ConnectionString = 
        builder.Configuration.GetConnectionString("DefaultConnection");   #2
    options.SchemaName = "dbo";                                           #2
    options.TableName = "AppCache";                                       #2
});

Register the provider with AddDistributedSqlServerCache, reuse DefaultConnection, and direct cache entries to dbo.AppCache. section 8.4.2

Complete the setup in these steps:

  • Install the Microsoft.Extensions.Caching.SqlServer NuGet package. section 8.4.2
  • Install the version-matched dotnet-sql-cache tool and run sql-cache create with the connection string, dbo schema, and AppCache table. section 8.4.2
  • Inject IDistributedCache into an API controller, derive a request-based cache key, retrieve cached results, and cache database query results with an expiration. section 8.4.2

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Walks through package installation, service registration, table creation, dependency injection, cache keys, expiration, and retrieval.
Examples
Uses dbo.AppCache, DefaultConnection, AddDistributedSqlServerCache, and a thirty-second Mechanics query-cache expiration.
What it assumes
Assumes familiarity with NuGet, Program.cs, connection strings, dependency injection, and basic SQL Server access.
What you can do after
Operate/configure SQL Server-backed caching and apply it to controller query results.
How it connects
Connects IDistributedCache with SQL Server, EF Core connection strings, ASP.NET dependency injection, and the dotnet CLI.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.