The Distributed Cache Tag Helper provides the ability to dramatically improve the performance of your ASP.NET Core app by caching its content to a distributed cache source.
The Distributed Cache Tag Helper inherits from the same base class as the Cache Tag Helper. All attributes associated with the Cache Tag Helper will also work on the Distributed Tag Helper.
The Distributed Cache Tag Helper follows the Explicit Dependencies Principle known as Constructor Injection. Specifically, the
IDistributedCache interface container is passed into the Distributed Cache Tag Helper's constructor. If no specific concrete implementation of
IDistributedCache has been created in
ConfigureServices, usually found in startup.cs, then the Distributed Cache Tag Helper will use the same in-memory provider for storing cached data as the basic Cache Tag Helper.
Distributed Cache Tag Helper Attributes
enabled expires-on expires-after expires-sliding vary-by-header vary-by-query vary-by-route vary-by-cookie vary-by-user vary-by priority
See Cache Tag Helper for definitions. Distributed Cache Tag Helper inherits from the same class as Cache Tag Helper so all these attributes are common from Cache Tag Helper.
|Attribute Type||Example Value|
name attribute is used as a key to that cache stored for each instance of a Distributed Cache Tag Helper. Unlike the basic Cache Tag Helper that assigns a key to each Cache Tag Helper instance based on the Razor page name and location of the tag helper in the razor page, the Distributed Cache Tag Helper only bases it's key on the attribute
<distributed-cache name="my-distributed-cache-unique-key-101"> Time Inside Cache Tag Helper: @DateTime.Now </distributed-cache>
Distributed Cache Tag Helper IDistributedCache Implementations
There are two implementations of
IDistributedCache built in to ASP.NET Core. One is based on Sql Server and the other is based on Redis. Details of these implementations can be found at the resource referenced below named "Working with a distributed cache". Both implementations involve setting an instance of
IDistributedCache in ASP.NET Core's startup.cs.
There are no tag attributes specifically associated with using any specific implementation of