IDistributedCache is the ASP.NET Core abstraction for storing and retrieving cached data through an external provider. Unlike in-memory caching, it lets multiple web servers share cache data without relying on local memory. section 8.0 section 8.6
Use IDistributedCache when the application needs provider-independent distributed storage:
- Choose a DBMS such as SQL Server or a distributed key-value store such as Redis or NCache. section 8.4.1
- Register the provider through its NuGet package; the package implements the common IDistributedCache interface. section 8.4.1
- Add generic helper methods when working with entities, because the base interface handles strings and byte arrays rather than typed values. section 8.4.2
- Inject IDistributedCache into a controller and use a stable key to read cached results before querying the database. section 8.4.2
Caching a paged mechanics query
A MechanicsController builds a cache key from the request type and serialized request values, then calls TryGetValue<Mechanic[]> before querying. On a miss, it filters, sorts, pages, and loads the data, stores the result for 30 seconds, and returns it. 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
});
Configure a distributed SQL Server cache with the application connection string, dbo schema, and AppCache table. section 8.4.2

