diff --git a/src/Umbraco.Core/Cache/HttpRequestCacheProvider.cs b/src/Umbraco.Core/Cache/HttpRequestCacheProvider.cs index 0ade5d55f4..0a95ff6fd2 100644 --- a/src/Umbraco.Core/Cache/HttpRequestCacheProvider.cs +++ b/src/Umbraco.Core/Cache/HttpRequestCacheProvider.cs @@ -2,7 +2,6 @@ using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Threading; using System.Web; namespace Umbraco.Core.Cache @@ -106,7 +105,7 @@ namespace Umbraco.Core.Cache if (result == null || GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null { - result = new Lazy(getCacheItem, LazyThreadSafetyMode.PublicationOnly); + result = new Lazy(getCacheItem); ContextItems[cacheKey] = result; } } diff --git a/src/Umbraco.Core/Cache/HttpRuntimeCacheProvider.cs b/src/Umbraco.Core/Cache/HttpRuntimeCacheProvider.cs index 00c2008da0..c5870f26e8 100644 --- a/src/Umbraco.Core/Cache/HttpRuntimeCacheProvider.cs +++ b/src/Umbraco.Core/Cache/HttpRuntimeCacheProvider.cs @@ -129,17 +129,11 @@ namespace Umbraco.Core.Cache if (result == null || GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null { + result = new Lazy(getCacheItem); var absolute = isSliding ? System.Web.Caching.Cache.NoAbsoluteExpiration : (timeout == null ? System.Web.Caching.Cache.NoAbsoluteExpiration : DateTime.Now.Add(timeout.Value)); var sliding = isSliding == false ? System.Web.Caching.Cache.NoSlidingExpiration : (timeout ?? System.Web.Caching.Cache.NoSlidingExpiration); lck.UpgradeToWriteLock(); - - result = new Lazy(getCacheItem, - //NOTE: This is required to not cache any exceptions that throw when the callback is executed. - // we want to ensure the callback is re-executed and not cached in the case that it might no - // longer throw an exception if runtime circumstances have changed. - LazyThreadSafetyMode.PublicationOnly); - _cache.Insert(cacheKey, result, dependency, absolute, sliding, priority, removedCallback); } } @@ -179,12 +173,7 @@ namespace Umbraco.Core.Cache // 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. - var result = new Lazy(getCacheItem, - //NOTE: This is required to not cache any exceptions that throw when the callback is executed. - // we want to ensure the callback is re-executed and not cached in the case that it might no - // longer throw an exception if runtime circumstances have changed. - LazyThreadSafetyMode.PublicationOnly); - + var result = new Lazy(getCacheItem); var value = result.Value; // force evaluation now - this may throw if cacheItem throws, and then nothing goes into cache if (value == null) return; // do not store null values (backward compat) diff --git a/src/Umbraco.Core/Cache/ObjectCacheRuntimeCacheProvider.cs b/src/Umbraco.Core/Cache/ObjectCacheRuntimeCacheProvider.cs index 13b987df63..edf1ba5aa6 100644 --- a/src/Umbraco.Core/Cache/ObjectCacheRuntimeCacheProvider.cs +++ b/src/Umbraco.Core/Cache/ObjectCacheRuntimeCacheProvider.cs @@ -207,14 +207,10 @@ namespace Umbraco.Core.Cache result = MemoryCache.Get(cacheKey) as Lazy; if (result == null || GetSafeLazyValue(result, true) == null) // get non-created as NonCreatedValue & exceptions as null { + result = new Lazy(getCacheItem); var policy = GetPolicy(timeout, isSliding, removedCallback, dependentFiles); lck.UpgradeToWriteLock(); - result = new Lazy(getCacheItem, - //NOTE: This is required to not cache any exceptions that throw when the callback is executed. - // we want to ensure the callback is re-executed and not cached in the case that it might no - // longer throw an exception if runtime circumstances have changed. - LazyThreadSafetyMode.PublicationOnly); MemoryCache.Set(cacheKey, result, policy); } } @@ -231,11 +227,7 @@ namespace Umbraco.Core.Cache // 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. - var result = new Lazy(getCacheItem, - //NOTE: This is required to not cache any exceptions that throw when the callback is executed. - // we want to ensure the callback is re-executed and not cached in the case that it might no - // longer throw an exception if runtime circumstances have changed. - LazyThreadSafetyMode.PublicationOnly); + var result = new Lazy(getCacheItem); var value = result.Value; // force evaluation now if (value == null) return; // do not store null values (backward compat) diff --git a/src/Umbraco.Tests/Cache/CacheProviderTests.cs b/src/Umbraco.Tests/Cache/CacheProviderTests.cs index 8eab3b4bde..b0a8aec68c 100644 --- a/src/Umbraco.Tests/Cache/CacheProviderTests.cs +++ b/src/Umbraco.Tests/Cache/CacheProviderTests.cs @@ -1,5 +1,4 @@ -using System; -using System.Linq; +using System.Linq; using System.Web.UI; using NUnit.Framework; using Umbraco.Core.Cache; @@ -24,59 +23,6 @@ namespace Umbraco.Tests.Cache Provider.ClearAllCache(); } - [Test] - public void Does_Not_Cache_Exceptions() - { - var counter = 0; - - object result; - try - { - result = Provider.GetCacheItem("Blah", () => - { - counter++; - throw new Exception("Do not cache this"); - }); - } - catch (Exception){} - - try - { - result = Provider.GetCacheItem("Blah", () => - { - counter++; - throw new Exception("Do not cache this"); - }); - } - catch (Exception){} - - Assert.Greater(counter, 1); - - } - - [Test] - public void Ensures_Delegate_Result_Is_Cached_Once() - { - var counter = 0; - - object result; - - result = Provider.GetCacheItem("Blah", () => - { - counter++; - return ""; - }); - - result = Provider.GetCacheItem("Blah", () => - { - counter++; - return ""; - }); - - Assert.AreEqual(counter, 1); - - } - [Test] public void Can_Get_By_Search() {