Skip to content

Commit e1df6b1

Browse files
author
Warren Buckley
committed
Update readme with some more examples to show use cases of our-cache tag
1 parent 9c48ccd commit e1df6b1

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,49 @@ 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 by the last Content/Media/Dictionary Cache Refresh date.
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.
361361

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

366-
With this set to true any publish will trigger a new 'cache key' and therefore a fresh version of the TagOutput will be displayed, with this set, and if no ExpiresAfter is set on the Tag, we default to 24hrs as the lifetime of the Tag's cache.
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.
367367

368-
This is set to True by default, how opinionated of us.
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.
369+
370+
### 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.
372+
373+
```cshtml
374+
<our-cache expires-on="new DateTime(2025,1,29,17,02,0)">
375+
<p>@DateTime.Now - A set Date in time</p>
376+
</our-cache>
377+
378+
<our-cache expires-after="TimeSpan.FromSeconds(120)">
379+
<p>@DateTime.Now - Every 120 seconds (2minutes)</p>
380+
</our-cache>
381+
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+
397+
<our-cache>
398+
<!-- Default of 20mins Global navigation -->
399+
<!-- A global naviagtion need to clear cache when phone number changes on different node -->
400+
<partial name="Navigation" />
401+
</our-cache>
402+
```
369403

370404
(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)
371405

0 commit comments

Comments
 (0)