Skip to content

Commit 21d7f92

Browse files
committed
Update Cache tag helper text and examples
1 parent c25cf36 commit 21d7f92

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

README.md

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -357,18 +357,16 @@ Essentially this is a convenience for setting
357357
'''
358358

359359
### Clearing the Cache 'on publish'
360-
The DotNet CacheTagHelper really isn't designed to make it easy to clear the cache 'on command' it's designed to vary and then fall out of cache after a period of time, but what if you want your cache instantly refreshed when a publish takes place? This tag helper has the possibility to 'vary' the cache when a piece of content/media or dictionary is published.
360+
The Umbraco convention with other Cache Helpers, eg Html.CachedPartial is to clear all memory caches whenever any item is published in the Umbraco Backoffice. By default the our-cache tag helper will do the same, however you can turn this part off on an individual TagHelper basis by setting update-cache-key-on-publish="false".
361361

362362
'''cshtml
363-
<our-cache update-cache-key-on-publish="true">[Your Long Running Expensive Code Here]</our-cache>
363+
<our-cache update-cache-key-on-publish="false">[Your Long Running Expensive Code Here]</our-cache>
364364
'''
365365

366-
With this set to true any publish will remove the item from a list of tracked cached items and therefore a fresh version of the TagOutput will be displayed.
367-
368-
This is set to True by default, how opinionated of us, so you only need to explictly use the attrivute if you wish to set this to false and not clear the cache item on Umbraco content/media/dictionary publish.
366+
(NB if you had a thousand tag helpers on your site, all caching large amounts of content, and new publishes to the site occurring every second - this might be detrimental to performance, so do think of the context of your site before allowing the cache to be cleared on each publish)
369367

370368
### Examples
371-
All examples will skip the cache for Umbraco preview mode and debug mode, and evicit cache items anytime Umbraco publishes content, media or dictionary items.
369+
All examples will skip the cache for Umbraco preview mode and debug mode, and evict cache items anytime Umbraco publishes content, media or dictionary items.
372370

373371
```cshtml
374372
<our-cache expires-on="new DateTime(2025,1,29,17,02,0)">
@@ -379,30 +377,18 @@ All examples will skip the cache for Umbraco preview mode and debug mode, and ev
379377
<p>@DateTime.Now - Every 120 seconds (2minutes)</p>
380378
</our-cache>
381379
382-
<our-cache vary-by="@Model.UpdateDate.ToString()">
383-
<!--
384-
Note the original cache taghelper would only clear the cache
385-
when the current page model UpdateDate changed.
386-
387-
Now we will ALSO clear the cache
388-
-->
389-
<p>@DateTime.Now - When Model.UpdateDate changes</p>
390-
</our-cache>
391-
392-
<our-cache vary-by="@Model.UpdateDate.ToString()">
393-
<!-- Global navigation -->
394-
<!-- Need to clear cache when phone number changes on different node -->
395-
</our-cache>
396-
397380
<our-cache>
398-
<!-- Default of 20mins Global navigation -->
399-
<!-- A global naviagtion need to clear cache when phone number changes on different node -->
381+
<!-- A global naviagtion needs to be updated across entire site when phone number changes on homepage node -->
400382
<partial name="Navigation" />
401383
</our-cache>
402-
```
403-
404-
(NB if you had a thousand tag helpers on your site, all caching large amounts of content, and new publishes to the site occurring every second - this might be detrimental to performance, so do think of the context of your site before setting this value)
405384
385+
```
386+
This example will turn off the automatic clearing of the tag helper cache if 'any page' is published, but still clear the cache if the individual page is published:
387+
```cshtml
388+
<our-cache update-cache-key-on-publish="false" vary-by="@Model.UpdateDate.ToString()">
389+
<p>@DateTime.Now - A set Date in time</p>
390+
</our-cache>
391+
```
406392

407393
## Video 📺
408394
[![How to create ASP.NET TagHelpers for Umbraco](https://user-images.githubusercontent.com/1389894/138666925-15475216-239f-439d-b989-c67995e5df71.png)](https://www.youtube.com/watch?v=3fkDs0NwIE8)

0 commit comments

Comments
 (0)