|
10 | 10 | namespace Our.Umbraco.TagHelpers
|
11 | 11 | {
|
12 | 12 | /// <summary>
|
13 |
| - /// A wrapper around .net core CacheTagHelper so you remember not to cache in preview or Umbraco debug mode |
14 |
| - /// Also can create a new variance of the cache when anything is published in Umbraco if that is desirable |
| 13 | + /// A wrapper around .net core CacheTagHelper, that is Umbraco Aware - so won't cache in Preview or Debug Mode |
| 14 | + /// And will automatically clear it's when anything is published (optional) |
15 | 15 | /// </summary>
|
16 | 16 | [HtmlTargetElement("our-cache")]
|
17 | 17 | public class UmbracoCacheTagHelper : CacheTagHelper
|
@@ -43,19 +43,23 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
|
43 | 43 | // we don't want to enable the cache tag helper if Umbraco is in Preview, or in Debug mode
|
44 | 44 | if (umbracoContext.InPreviewMode || umbracoContext.IsDebug)
|
45 | 45 | {
|
46 |
| - // Set the endabled flag to false & lest base class |
47 |
| - // of the cache tag helper do the same stuff as before |
| 46 | + // Set the enabled flag to false & let base class |
| 47 | + // of the cache tag helper do the disabling of the cache |
48 | 48 | this.Enabled = false;
|
49 | 49 | }
|
50 | 50 | else
|
51 | 51 | {
|
52 |
| - // Defaults to true - have to explicitly opt out with attribute set to false in Razor |
| 52 | + // Now whenever anything is published in Umbraco 'the old Umbraco Cache Helper convention' was to clear out all the view memory caches |
| 53 | + // we want to do the same by default for this tag helper |
| 54 | + // we can't track by convention as dot net tag helper cache key is hashed - but we can generte the hash key here, and add it to a dictionary |
| 55 | + // which we can loop through when the Umbraco cache is updated to clear the tag helper cache. |
| 56 | + // you can opt out of this by setting update-cache-key-on-publish="false" in the individual tag helper |
53 | 57 | if (UpdateCacheKeyOnPublish)
|
54 | 58 | {
|
55 |
| - // So before we go into our base class |
56 |
| - // Grab the cache key so we can keep track of it & put into some dictionary or collection |
| 59 | + // The base TagHelper would generate it's own CacheTagKey to create a unique hash |
| 60 | + // but if we call it here 'too' it will fortunately be the same hash. |
| 61 | + // so we can keep track of it & put into some dictionary or collection |
57 | 62 | // and clear all items out in that collection with our notifications on publish
|
58 |
| - |
59 | 63 | var cacheKey = new CacheTagKey(this, context);
|
60 | 64 | var key = cacheKey.GenerateKey();
|
61 | 65 | var hashedKey = cacheKey.GenerateHashedKey();
|
|
0 commit comments