"
 
 
 
ASP.NET (snapshot 2017) Microsoft documentation and samples

Distributed Cache Tag Helper

By Peter Kellner

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


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.


name (required)

Attribute Type Example Value
string “my-distributed-cache-unique-key-101”

The required 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 name

Usage Example:

<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 IDistributedCache.


Additional resources





Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23
Link to this page: //www.vb-net.com/AspNet-DocAndSamples-2017/aspnetcore/mvc/views/tag-helpers/built-in/distributed-cache-tag-helper.htm
<SITEMAP>  <MVC>  <ASP>  <NET>  <DATA>  <KIOSK>  <FLEX>  <SQL>  <NOTES>  <LINUX>  <MONO>  <FREEWARE>  <DOCS>  <ENG>  <CHAT ME>  <ABOUT ME>  < THANKS ME>