The Cache Tag Helper provides the ability to improve the performance of your ASP.NET Core app by caching its content to the internal ASP.NET Core cache provider.
The cache tag helper enables you to cache regions of a Razor page in memory on the server. Typical uses for this helper are for View Components or partial views that require relatively expensive database or web service calls, but where the content doesn't change very often. This type of caching its primarily used to improve a website's performance.
Unlike most other tag helpers, the Cache tag helper doesn't target a standard HTML element. It targets the <cache> tag, which is not rendered to the browser and doesn't appear in the HTML source either.
The following Razor markup caches the current date:
<cache>@DateTime.Now</cache>
The first request to the page that contains the Tag Helper displays the current date. Additional requests show the cached value until the cache expires (default 20 minutes) or until the cached date is evicted from the cache.
enabled
- Used to specify if this tag is enabled or notexpires-after
- Specifies the period of time after which the cached item should expireexpires-on
- Specifies the time at which the cached entry should expireexpires-sliding
- The period of time after the last access that the item should expirepriority
- Specifies the CacheItemPriority value of the cached itemvary-by
- Used to specify the parameters that determine whether different versions of the same content should be cachedThe following resources provide information for the Cache Tag Helper in ASP.NET Core