diff --git a/src/Orchard.Web/Modules/Orchard.OutputCache/Services/CacheService.cs b/src/Orchard.Web/Modules/Orchard.OutputCache/Services/CacheService.cs index 5aee5d092..2be361bf9 100644 --- a/src/Orchard.Web/Modules/Orchard.OutputCache/Services/CacheService.cs +++ b/src/Orchard.Web/Modules/Orchard.OutputCache/Services/CacheService.cs @@ -37,11 +37,8 @@ namespace Orchard.OutputCache.Services { } public void RemoveByTag(string tag) { - Collection itemKeys; - if (_tagCache.TryGetValue(tag, out itemKeys)) { - foreach (var key in itemKeys) { - _cacheStorageProvider.Remove(key); - } + foreach(var key in _tagCache.GetTaggedItems(tag)) { + _cacheStorageProvider.Remove(key); } } diff --git a/src/Orchard.Web/Modules/Orchard.OutputCache/Services/DefaultTagCache.cs b/src/Orchard.Web/Modules/Orchard.OutputCache/Services/DefaultTagCache.cs index 7abaee684..45a4a9d71 100644 --- a/src/Orchard.Web/Modules/Orchard.OutputCache/Services/DefaultTagCache.cs +++ b/src/Orchard.Web/Modules/Orchard.OutputCache/Services/DefaultTagCache.cs @@ -1,24 +1,41 @@ using System; using System.Collections.Concurrent; -using System.Collections.ObjectModel; +using System.Collections.Generic; +using System.Linq; using Orchard.OutputCache.Models; +using Orchard.Utility.Extensions; namespace Orchard.OutputCache.Services { /// /// Tenant wide case insensitive reverse index for tags. /// - public class DefaultTagCache : ConcurrentDictionary>, ITagCache { - public DefaultTagCache() : base(StringComparer.OrdinalIgnoreCase) { + public class DefaultTagCache : ITagCache { + + private readonly ConcurrentDictionary> _dictionary; + + public DefaultTagCache() { + _dictionary = new ConcurrentDictionary>(StringComparer.OrdinalIgnoreCase); } public void Tag(string tag, params string[] keys) { - var collection = GetOrAdd(tag, x => new Collection()); + var set = _dictionary.GetOrAdd(tag, x => new HashSet()); - foreach (var key in keys) { - if (!collection.Contains(key)) { - collection.Add(key); + lock (set) { + foreach (var key in keys) { + set.Add(key); } } } + + public IEnumerable GetTaggedItems(string tag) { + HashSet set; + if (_dictionary.TryGetValue(tag, out set)) { + lock (set) { + return set.ToReadOnlyCollection(); + } + } + + return Enumerable.Empty(); + } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.OutputCache/Services/ITagCache.cs b/src/Orchard.Web/Modules/Orchard.OutputCache/Services/ITagCache.cs index 916c136e1..a0fcc46d0 100644 --- a/src/Orchard.Web/Modules/Orchard.OutputCache/Services/ITagCache.cs +++ b/src/Orchard.Web/Modules/Orchard.OutputCache/Services/ITagCache.cs @@ -1,9 +1,8 @@ using System.Collections.Generic; -using System.Collections.ObjectModel; -using Orchard; namespace Orchard.OutputCache.Services { - public interface ITagCache : IDictionary>, ISingletonDependency { + public interface ITagCache : ISingletonDependency { void Tag(string tag, params string[] keys); + IEnumerable GetTaggedItems(string tag); } } \ No newline at end of file