Skip to content

Commit 40a8aaa

Browse files
author
David Peck
committed
Make UmbracoTagHelperCacheKeys Threadsafe
1 parent 1345a60 commit 40a8aaa

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using Microsoft.AspNetCore.Mvc.TagHelpers.Cache;
2-
using System.Collections.Generic;
2+
using System.Collections.Concurrent;
33

44
namespace Our.Umbraco.TagHelpers.Services
55
{
66
public interface IUmbracoTagHelperCacheKeys
77
{
8-
Dictionary<string, CacheTagKey> CacheKeys { get; }
8+
ConcurrentDictionary<string, CacheTagKey> CacheKeys { get; }
99
}
1010
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Microsoft.AspNetCore.Mvc.TagHelpers.Cache;
2-
using System.Collections.Generic;
2+
using System.Collections.Concurrent;
33

44
namespace Our.Umbraco.TagHelpers.Services
55
{
@@ -9,6 +9,6 @@ namespace Our.Umbraco.TagHelpers.Services
99
/// </summary>
1010
public class UmbracoTagHelperCacheKeys : IUmbracoTagHelperCacheKeys
1111
{
12-
public Dictionary<string,CacheTagKey> CacheKeys { get; } = new Dictionary<string,CacheTagKey>();
12+
public ConcurrentDictionary<string,CacheTagKey> CacheKeys { get; } = new ConcurrentDictionary<string,CacheTagKey>();
1313
}
1414
}

Our.Umbraco.TagHelpers/UmbracoCacheTagHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.AspNetCore.Mvc.TagHelpers.Cache;
33
using Microsoft.AspNetCore.Razor.TagHelpers;
44
using Our.Umbraco.TagHelpers.Services;
5+
using System.Collections.Generic;
56
using System.Text.Encodings.Web;
67
using System.Threading.Tasks;
78
using Umbraco.Cms.Core;
@@ -62,7 +63,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
6263
// and clear all items out in that collection with our notifications on publish
6364
var cacheKey = new CacheTagKey(this, context);
6465
var key = cacheKey.GenerateKey();
65-
var hashedKey = cacheKey.GenerateHashedKey();
66+
_ = cacheKey.GenerateHashedKey();
6667
_cacheKeys.CacheKeys.TryAdd(key, cacheKey);
6768
}
6869
}

0 commit comments

Comments
 (0)