From 235f6fbc54d1852abc85ffbb47bd241ccd452e95 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 18:57:40 +1100 Subject: [PATCH] moves DictionaryAppCache --- .../Cache/DictionaryAppCache.cs | 26 ++++++++++--------- src/Umbraco.Core/Umbraco.Core.csproj | 1 - .../Cache/HttpRequestAppCacheTests.cs | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) rename src/{Umbraco.Core => Umbraco.Abstractions}/Cache/DictionaryAppCache.cs (71%) diff --git a/src/Umbraco.Core/Cache/DictionaryAppCache.cs b/src/Umbraco.Abstractions/Cache/DictionaryAppCache.cs similarity index 71% rename from src/Umbraco.Core/Cache/DictionaryAppCache.cs rename to src/Umbraco.Abstractions/Cache/DictionaryAppCache.cs index 8889630ff0..6e528165a0 100644 --- a/src/Umbraco.Core/Cache/DictionaryAppCache.cs +++ b/src/Umbraco.Abstractions/Cache/DictionaryAppCache.cs @@ -13,25 +13,27 @@ namespace Umbraco.Core.Cache /// /// Gets the internal items dictionary, for tests only! /// - internal readonly ConcurrentDictionary Items = new ConcurrentDictionary(); + private readonly ConcurrentDictionary _items = new ConcurrentDictionary(); + + public int Count => _items.Count; /// public virtual object Get(string key) { - return Items.TryGetValue(key, out var value) ? value : null; + return _items.TryGetValue(key, out var value) ? value : null; } /// public virtual object Get(string key, Func factory) { - return Items.GetOrAdd(key, _ => factory()); + return _items.GetOrAdd(key, _ => factory()); } /// public virtual IEnumerable SearchByKey(string keyStartsWith) { var items = new List(); - foreach (var (key, value) in Items) + foreach (var (key, value) in _items) if (key.InvariantStartsWith(keyStartsWith)) items.Add(value); return items; @@ -42,7 +44,7 @@ namespace Umbraco.Core.Cache { var compiled = new Regex(regex, RegexOptions.Compiled); var items = new List(); - foreach (var (key, value) in Items) + foreach (var (key, value) in _items) if (compiled.IsMatch(key)) items.Add(value); return items; @@ -51,46 +53,46 @@ namespace Umbraco.Core.Cache /// public virtual void Clear() { - Items.Clear(); + _items.Clear(); } /// public virtual void Clear(string key) { - Items.TryRemove(key, out _); + _items.TryRemove(key, out _); } /// public virtual void ClearOfType(string typeName) { - Items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType().ToString().InvariantEquals(typeName)); + _items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType().ToString().InvariantEquals(typeName)); } /// public virtual void ClearOfType() { var typeOfT = typeof(T); - Items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT); + _items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT); } /// public virtual void ClearOfType(Func predicate) { var typeOfT = typeof(T); - Items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT && predicate(kvp.Key, (T)kvp.Value)); + _items.RemoveAll(kvp => kvp.Value != null && kvp.Value.GetType() == typeOfT && predicate(kvp.Key, (T)kvp.Value)); } /// public virtual void ClearByKey(string keyStartsWith) { - Items.RemoveAll(kvp => kvp.Key.InvariantStartsWith(keyStartsWith)); + _items.RemoveAll(kvp => kvp.Key.InvariantStartsWith(keyStartsWith)); } /// public virtual void ClearByRegex(string regex) { var compiled = new Regex(regex, RegexOptions.Compiled); - Items.RemoveAll(kvp => compiled.IsMatch(kvp.Key)); + _items.RemoveAll(kvp => compiled.IsMatch(kvp.Key)); } } } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 644d30d38e..b8ebde64cf 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -143,7 +143,6 @@ - diff --git a/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs b/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs index 0be38d2c55..042830e059 100644 --- a/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs +++ b/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs @@ -46,7 +46,7 @@ namespace Umbraco.Tests.Cache protected override int GetTotalItemCount { - get { return _appCache.Items.Count; } + get { return _appCache.Count; } } } }