<our-cache>
<our-cache> is ASP.NET Core’s cache tag helper with two Umbraco additions:
- It’s turned off in Umbraco preview and debug mode, so editors always see their latest changes.
- Its cache is cleared whenever content, media or dictionary items are published.
It takes all the same attributes as <cache>, such as expires-after and vary-by.
Before and after
Section titled “Before and after”<cache enabled="!UmbracoContext.IsDebug && !UmbracoContext.InPreviewMode">[Your long running, expensive code here]</cache><our-cache>[Your long running, expensive code here]</our-cache>Examples
Section titled “Examples”<our-cache expires-on="new DateTime(2025,1,29,17,02,0)"> <p>@DateTime.Now - until a set date and time</p></our-cache>
<our-cache expires-after="TimeSpan.FromSeconds(120)"> <p>@DateTime.Now - every 120 seconds (2 minutes)</p></our-cache>
<our-cache> <!-- A global navigation that must update across the site when, say, the phone number on the home page changes --> <partial name="Navigation" /></our-cache>Clearing the cache on publish
Section titled “Clearing the cache on publish”Like Umbraco’s other cache helpers, such as Html.CachedPartial, the cache is cleared every time anything is published. That’s the same as writing:
<our-cache update-cache-on-publish="true">[Your long running, expensive code here]</our-cache>To turn it off for one tag:
<our-cache update-cache-on-publish="false">[Your long running, expensive code here]</our-cache>You can still clear it when one page is published by varying by that page’s update date:
<our-cache update-cache-on-publish="false" vary-by="@Model.UpdateDate.ToString()"> <p>@DateTime.Now</p></our-cache>