From 5ec78cd510ade4018aa3e2030eb134dd59b1a7d5 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 7 Nov 2019 18:29:16 +1100 Subject: [PATCH] Removes totally unused CacheItemRemovedCallback --- src/Umbraco.Core/Cache/AppCacheExtensions.cs | 4 +- src/Umbraco.Core/Cache/DeepCloneAppCache.cs | 8 ++-- src/Umbraco.Core/Cache/IAppPolicyCache.cs | 4 -- src/Umbraco.Core/Cache/NoAppCache.cs | 4 +- src/Umbraco.Core/Cache/ObjectCacheAppCache.cs | 38 +++---------------- src/Umbraco.Core/Cache/WebCachingAppCache.cs | 16 ++++---- src/Umbraco.Core/Umbraco.Core.csproj | 2 +- .../Cache/DefaultCachePolicyTests.cs | 4 +- .../Cache/FullDataSetCachePolicyTests.cs | 6 +-- .../Cache/SingleItemsOnlyCachePolicyTests.cs | 4 +- 10 files changed, 29 insertions(+), 61 deletions(-) diff --git a/src/Umbraco.Core/Cache/AppCacheExtensions.cs b/src/Umbraco.Core/Cache/AppCacheExtensions.cs index ddba8be1b2..286b6bd54d 100644 --- a/src/Umbraco.Core/Cache/AppCacheExtensions.cs +++ b/src/Umbraco.Core/Cache/AppCacheExtensions.cs @@ -19,7 +19,7 @@ namespace Umbraco.Core.Cache CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) { - var result = provider.Get(cacheKey, () => getCacheItem(), timeout, isSliding, priority, removedCallback, dependentFiles); + var result = provider.Get(cacheKey, () => getCacheItem(), timeout, isSliding, priority, dependentFiles); return result == null ? default(T) : result.TryConvertTo().Result; } @@ -32,7 +32,7 @@ namespace Umbraco.Core.Cache CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) { - provider.Insert(cacheKey, () => getCacheItem(), timeout, isSliding, priority, removedCallback, dependentFiles); + provider.Insert(cacheKey, () => getCacheItem(), timeout, isSliding, priority, dependentFiles); } public static IEnumerable GetCacheItemsByKeySearch(this IAppCache provider, string keyStartsWith) diff --git a/src/Umbraco.Core/Cache/DeepCloneAppCache.cs b/src/Umbraco.Core/Cache/DeepCloneAppCache.cs index eff06e2aad..a934f32dbf 100644 --- a/src/Umbraco.Core/Cache/DeepCloneAppCache.cs +++ b/src/Umbraco.Core/Cache/DeepCloneAppCache.cs @@ -67,7 +67,7 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { var cached = InnerCache.Get(key, () => { @@ -77,14 +77,14 @@ namespace Umbraco.Core.Cache return value == null ? null : CheckCloneableAndTracksChanges(value); // clone / reset to go into the cache - }, timeout, isSliding, priority, removedCallback, dependentFiles); + }, timeout, isSliding, priority, dependentFiles); // clone / reset to go into the cache return CheckCloneableAndTracksChanges(cached); } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { InnerCache.Insert(key, () => { @@ -92,7 +92,7 @@ namespace Umbraco.Core.Cache var value = result.Value; // force evaluation now - this may throw if cacheItem throws, and then nothing goes into cache // do not store null values (backward compat), clone / reset to go into the cache return value == null ? null : CheckCloneableAndTracksChanges(value); - }, timeout, isSliding, priority, removedCallback, dependentFiles); + }, timeout, isSliding, priority, dependentFiles); } /// diff --git a/src/Umbraco.Core/Cache/IAppPolicyCache.cs b/src/Umbraco.Core/Cache/IAppPolicyCache.cs index dd162b990d..6b09037fa1 100644 --- a/src/Umbraco.Core/Cache/IAppPolicyCache.cs +++ b/src/Umbraco.Core/Cache/IAppPolicyCache.cs @@ -18,7 +18,6 @@ namespace Umbraco.Core.Cache /// An optional cache timeout. /// An optional value indicating whether the cache timeout is sliding (default is false). /// An optional cache priority (default is Normal). - /// An optional callback to handle removals. /// Files the cache entry depends on. /// The item. object Get( @@ -27,7 +26,6 @@ namespace Umbraco.Core.Cache TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, - CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null); /// @@ -38,7 +36,6 @@ namespace Umbraco.Core.Cache /// An optional cache timeout. /// An optional value indicating whether the cache timeout is sliding (default is false). /// An optional cache priority (default is Normal). - /// An optional callback to handle removals. /// Files the cache entry depends on. void Insert( string key, @@ -46,7 +43,6 @@ namespace Umbraco.Core.Cache TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, - CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null); } } diff --git a/src/Umbraco.Core/Cache/NoAppCache.cs b/src/Umbraco.Core/Cache/NoAppCache.cs index d3359a30ba..336948bc83 100644 --- a/src/Umbraco.Core/Cache/NoAppCache.cs +++ b/src/Umbraco.Core/Cache/NoAppCache.cs @@ -42,13 +42,13 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { return factory(); } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { } /// diff --git a/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs b/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs index 5c4f76f51d..2701313423 100644 --- a/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs +++ b/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs @@ -103,7 +103,7 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { // see notes in HttpRuntimeAppCache @@ -115,7 +115,7 @@ namespace Umbraco.Core.Cache if (result == null || FastDictionaryAppCacheBase.GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null { result = FastDictionaryAppCacheBase.GetSafeLazy(factory); - var policy = GetPolicy(timeout, isSliding, removedCallback, dependentFiles); + var policy = GetPolicy(timeout, isSliding, dependentFiles); lck.UpgradeToWriteLock(); //NOTE: This does an add or update @@ -131,7 +131,7 @@ namespace Umbraco.Core.Cache } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { // NOTE - here also we must insert a Lazy but we can evaluate it right now // and make sure we don't store a null value. @@ -140,7 +140,7 @@ namespace Umbraco.Core.Cache var value = result.Value; // force evaluation now if (value == null) return; // do not store null values (backward compat) - var policy = GetPolicy(timeout, isSliding, removedCallback, dependentFiles); + var policy = GetPolicy(timeout, isSliding, dependentFiles); //NOTE: This does an add or update MemoryCache.Set(key, result, policy); } @@ -314,7 +314,7 @@ namespace Umbraco.Core.Cache } } - private static CacheItemPolicy GetPolicy(TimeSpan? timeout = null, bool isSliding = false, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + private static CacheItemPolicy GetPolicy(TimeSpan? timeout = null, bool isSliding = false, string[] dependentFiles = null) { var absolute = isSliding ? ObjectCache.InfiniteAbsoluteExpiration : (timeout == null ? ObjectCache.InfiniteAbsoluteExpiration : DateTime.Now.Add(timeout.Value)); var sliding = isSliding == false ? ObjectCache.NoSlidingExpiration : (timeout ?? ObjectCache.NoSlidingExpiration); @@ -330,34 +330,6 @@ namespace Umbraco.Core.Cache policy.ChangeMonitors.Add(new HostFileChangeMonitor(dependentFiles.ToList())); } - if (removedCallback != null) - { - policy.RemovedCallback = arguments => - { - //convert the reason - var reason = CacheItemRemovedReason.Removed; - switch (arguments.RemovedReason) - { - case CacheEntryRemovedReason.Removed: - reason = CacheItemRemovedReason.Removed; - break; - case CacheEntryRemovedReason.Expired: - reason = CacheItemRemovedReason.Expired; - break; - case CacheEntryRemovedReason.Evicted: - reason = CacheItemRemovedReason.Underused; - break; - case CacheEntryRemovedReason.ChangeMonitorChanged: - reason = CacheItemRemovedReason.Expired; - break; - case CacheEntryRemovedReason.CacheSpecificEviction: - reason = CacheItemRemovedReason.Underused; - break; - } - //call the callback - removedCallback(arguments.CacheItem.Key, arguments.CacheItem.Value, reason); - }; - } return policy; } } diff --git a/src/Umbraco.Core/Cache/WebCachingAppCache.cs b/src/Umbraco.Core/Cache/WebCachingAppCache.cs index c6e104221a..da3b5def1e 100644 --- a/src/Umbraco.Core/Cache/WebCachingAppCache.cs +++ b/src/Umbraco.Core/Cache/WebCachingAppCache.cs @@ -35,25 +35,25 @@ namespace Umbraco.Core.Cache } /// - public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { CacheDependency dependency = null; if (dependentFiles != null && dependentFiles.Any()) { dependency = new CacheDependency(dependentFiles); } - return Get(key, factory, timeout, isSliding, priority, removedCallback, dependency); + return GetImpl(key, factory, timeout, isSliding, priority, dependency); } /// - public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, string[] dependentFiles = null) + public void Insert(string key, Func factory, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, string[] dependentFiles = null) { CacheDependency dependency = null; if (dependentFiles != null && dependentFiles.Any()) { dependency = new CacheDependency(dependentFiles); } - Insert(key, factory, timeout, isSliding, priority, removedCallback, dependency); + InsertImpl(key, factory, timeout, isSliding, priority, dependency); } #region Dictionary @@ -103,7 +103,7 @@ namespace Umbraco.Core.Cache #endregion - private object Get(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, CacheDependency dependency = null) + private object GetImpl(string key, Func factory, TimeSpan? timeout, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheDependency dependency = null) { key = GetCacheKey(key); @@ -164,7 +164,7 @@ namespace Umbraco.Core.Cache lck.UpgradeToWriteLock(); //NOTE: 'Insert' on System.Web.Caching.Cache actually does an add or update! - _cache.Insert(key, result, dependency, absolute, sliding, priority, removedCallback); + _cache.Insert(key, result, dependency, absolute, sliding, priority, null); } } @@ -180,7 +180,7 @@ namespace Umbraco.Core.Cache return value; } - private void Insert(string cacheKey, Func getCacheItem, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheItemRemovedCallback removedCallback = null, CacheDependency dependency = null) + private void InsertImpl(string cacheKey, Func getCacheItem, TimeSpan? timeout = null, bool isSliding = false, CacheItemPriority priority = CacheItemPriority.Normal, CacheDependency dependency = null) { // NOTE - here also we must insert a Lazy but we can evaluate it right now // and make sure we don't store a null value. @@ -198,7 +198,7 @@ namespace Umbraco.Core.Cache { _locker.EnterWriteLock(); //NOTE: 'Insert' on System.Web.Caching.Cache actually does an add or update! - _cache.Insert(cacheKey, result, dependency, absolute, sliding, priority, removedCallback); + _cache.Insert(cacheKey, result, dependency, absolute, sliding, priority, null); } finally { diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 4f25848000..1721af376e 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -125,6 +125,7 @@ --> + @@ -140,7 +141,6 @@ - diff --git a/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs b/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs index 4161f576c9..ca91c63621 100644 --- a/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/DefaultCachePolicyTests.cs @@ -30,7 +30,7 @@ namespace Umbraco.Tests.Cache var isCached = false; var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + It.IsAny(), It.IsAny())) .Callback(() => { isCached = true; @@ -60,7 +60,7 @@ namespace Umbraco.Tests.Cache var cached = new List(); var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + It.IsAny(), It.IsAny())) .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => { cached.Add(cacheKey); diff --git a/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs b/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs index a4fbdf2224..f48974657c 100644 --- a/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/FullDataSetCachePolicyTests.cs @@ -39,7 +39,7 @@ namespace Umbraco.Tests.Cache var isCached = false; var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + It.IsAny(), It.IsAny())) .Callback(() => { isCached = true; @@ -80,7 +80,7 @@ namespace Umbraco.Tests.Cache var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + It.IsAny(), It.IsAny())) .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => { cached.Add(cacheKey); @@ -123,7 +123,7 @@ namespace Umbraco.Tests.Cache var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + It.IsAny(), It.IsAny())) .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => { cached.Add(cacheKey); diff --git a/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs b/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs index 2525eab45b..ea68873525 100644 --- a/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs +++ b/src/Umbraco.Tests/Cache/SingleItemsOnlyCachePolicyTests.cs @@ -30,7 +30,7 @@ namespace Umbraco.Tests.Cache var cached = new List(); var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + It.IsAny(), It.IsAny())) .Callback((string cacheKey, Func o, TimeSpan? t, bool b, CacheItemPriority cip, CacheItemRemovedCallback circ, string[] s) => { cached.Add(cacheKey); @@ -54,7 +54,7 @@ namespace Umbraco.Tests.Cache var isCached = false; var cache = new Mock(); cache.Setup(x => x.Insert(It.IsAny(), It.IsAny>(), It.IsAny(), It.IsAny(), - It.IsAny(), It.IsAny(), It.IsAny())) + It.IsAny(), It.IsAny())) .Callback(() => { isCached = true;