diff --git a/src/Umbraco.Core/Cache/CacheProviderExtensions.cs b/src/Umbraco.Core/Cache/AppCacheExtensions.cs similarity index 98% rename from src/Umbraco.Core/Cache/CacheProviderExtensions.cs rename to src/Umbraco.Core/Cache/AppCacheExtensions.cs index d943d19edb..ddba8be1b2 100644 --- a/src/Umbraco.Core/Cache/CacheProviderExtensions.cs +++ b/src/Umbraco.Core/Cache/AppCacheExtensions.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Cache /// /// Extensions for strongly typed access /// - public static class CacheProviderExtensions + public static class AppCacheExtensions { public static T GetCacheItem(this IAppPolicyCache provider, string cacheKey, diff --git a/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs b/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs index 449eb5d643..5c4f76f51d 100644 --- a/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs +++ b/src/Umbraco.Core/Cache/ObjectCacheAppCache.cs @@ -105,7 +105,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) { - // see notes in HttpRuntimeCacheProvider + // see notes in HttpRuntimeAppCache Lazy result; diff --git a/src/Umbraco.Core/Cache/WebCachingAppCache.cs b/src/Umbraco.Core/Cache/WebCachingAppCache.cs index 7fbdebf9ab..c6e104221a 100644 --- a/src/Umbraco.Core/Cache/WebCachingAppCache.cs +++ b/src/Umbraco.Core/Cache/WebCachingAppCache.cs @@ -9,7 +9,6 @@ namespace Umbraco.Core.Cache { /// /// Implements on top of a . - /// A CacheProvider that wraps the logic of the HttpRuntime.Cache /// /// The underlying cache is expected to be HttpRuntime.Cache. internal class WebCachingAppCache : FastDictionaryAppCacheBase, IAppPolicyCache diff --git a/src/Umbraco.Core/Composing/Current.cs b/src/Umbraco.Core/Composing/Current.cs index bfc5cfd51c..429fee3317 100644 --- a/src/Umbraco.Core/Composing/Current.cs +++ b/src/Umbraco.Core/Composing/Current.cs @@ -180,7 +180,7 @@ namespace Umbraco.Core.Composing public static ICultureDictionaryFactory CultureDictionaryFactory => Factory.GetInstance(); - public static AppCaches ApplicationCache + public static AppCaches AppCaches => Factory.GetInstance(); public static ServiceContext Services diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/MemberGroupRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/MemberGroupRepository.cs index 11166ce777..e6ee79470c 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/MemberGroupRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/MemberGroupRepository.cs @@ -124,7 +124,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement var result = Get(qry); return result.FirstOrDefault(); }, - //cache for 5 mins since that is the default in the RuntimeCacheProvider + //cache for 5 mins since that is the default in the Runtime app cache TimeSpan.FromMinutes(5), //sliding is true true); diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index b94c718242..5b2692359a 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -114,7 +114,7 @@ - + diff --git a/src/Umbraco.Tests/Cache/CacheProviderTests.cs b/src/Umbraco.Tests/Cache/AppCacheTests.cs similarity index 69% rename from src/Umbraco.Tests/Cache/CacheProviderTests.cs rename to src/Umbraco.Tests/Cache/AppCacheTests.cs index f2288cbaf2..f18e08d680 100644 --- a/src/Umbraco.Tests/Cache/CacheProviderTests.cs +++ b/src/Umbraco.Tests/Cache/AppCacheTests.cs @@ -7,9 +7,9 @@ using umbraco; namespace Umbraco.Tests.Cache { - public abstract class CacheProviderTests + public abstract class AppCacheTests { - internal abstract IAppCache Provider { get; } + internal abstract IAppCache AppCache { get; } protected abstract int GetTotalItemCount { get; } [SetUp] @@ -21,22 +21,22 @@ namespace Umbraco.Tests.Cache [TearDown] public virtual void TearDown() { - Provider.Clear(); + AppCache.Clear(); } [Test] public void Throws_On_Reentry() { // don't run for StaticCacheProvider - not making sense - if (GetType() == typeof (StaticCacheProviderTests)) + if (GetType() == typeof (StaticAppCacheTests)) Assert.Ignore("Do not run for StaticCacheProvider."); Exception exception = null; - var result = Provider.Get("blah", () => + var result = AppCache.Get("blah", () => { try { - var result2 = Provider.Get("blah"); + var result2 = AppCache.Get("blah"); } catch (Exception e) { @@ -56,7 +56,7 @@ namespace Umbraco.Tests.Cache object result; try { - result = Provider.Get("Blah", () => + result = AppCache.Get("Blah", () => { counter++; throw new Exception("Do not cache this"); @@ -66,7 +66,7 @@ namespace Umbraco.Tests.Cache try { - result = Provider.Get("Blah", () => + result = AppCache.Get("Blah", () => { counter++; throw new Exception("Do not cache this"); @@ -85,13 +85,13 @@ namespace Umbraco.Tests.Cache object result; - result = Provider.Get("Blah", () => + result = AppCache.Get("Blah", () => { counter++; return ""; }); - result = Provider.Get("Blah", () => + result = AppCache.Get("Blah", () => { counter++; return ""; @@ -108,14 +108,14 @@ namespace Umbraco.Tests.Cache var cacheContent2 = new MacroCacheContent(new LiteralControl(), "Test2"); var cacheContent3 = new MacroCacheContent(new LiteralControl(), "Test3"); var cacheContent4 = new LiteralControl(); - Provider.Get("Test1", () => cacheContent1); - Provider.Get("Tester2", () => cacheContent2); - Provider.Get("Tes3", () => cacheContent3); - Provider.Get("different4", () => cacheContent4); + AppCache.Get("Test1", () => cacheContent1); + AppCache.Get("Tester2", () => cacheContent2); + AppCache.Get("Tes3", () => cacheContent3); + AppCache.Get("different4", () => cacheContent4); Assert.AreEqual(4, GetTotalItemCount); - var result = Provider.SearchByKey("Tes"); + var result = AppCache.SearchByKey("Tes"); Assert.AreEqual(3, result.Count()); } @@ -127,14 +127,14 @@ namespace Umbraco.Tests.Cache var cacheContent2 = new MacroCacheContent(new LiteralControl(), "Test2"); var cacheContent3 = new MacroCacheContent(new LiteralControl(), "Test3"); var cacheContent4 = new LiteralControl(); - Provider.Get("TTes1t", () => cacheContent1); - Provider.Get("Tester2", () => cacheContent2); - Provider.Get("Tes3", () => cacheContent3); - Provider.Get("different4", () => cacheContent4); + AppCache.Get("TTes1t", () => cacheContent1); + AppCache.Get("Tester2", () => cacheContent2); + AppCache.Get("Tes3", () => cacheContent3); + AppCache.Get("different4", () => cacheContent4); Assert.AreEqual(4, GetTotalItemCount); - Provider.ClearByRegex("^\\w+es\\d.*"); + AppCache.ClearByRegex("^\\w+es\\d.*"); Assert.AreEqual(2, GetTotalItemCount); } @@ -146,14 +146,14 @@ namespace Umbraco.Tests.Cache var cacheContent2 = new MacroCacheContent(new LiteralControl(), "Test2"); var cacheContent3 = new MacroCacheContent(new LiteralControl(), "Test3"); var cacheContent4 = new LiteralControl(); - Provider.Get("Test1", () => cacheContent1); - Provider.Get("Tester2", () => cacheContent2); - Provider.Get("Tes3", () => cacheContent3); - Provider.Get("different4", () => cacheContent4); + AppCache.Get("Test1", () => cacheContent1); + AppCache.Get("Tester2", () => cacheContent2); + AppCache.Get("Tes3", () => cacheContent3); + AppCache.Get("different4", () => cacheContent4); Assert.AreEqual(4, GetTotalItemCount); - Provider.ClearByKey("Test"); + AppCache.ClearByKey("Test"); Assert.AreEqual(2, GetTotalItemCount); } @@ -165,15 +165,15 @@ namespace Umbraco.Tests.Cache var cacheContent2 = new MacroCacheContent(new LiteralControl(), "Test2"); var cacheContent3 = new MacroCacheContent(new LiteralControl(), "Test3"); var cacheContent4 = new LiteralControl(); - Provider.Get("Test1", () => cacheContent1); - Provider.Get("Test2", () => cacheContent2); - Provider.Get("Test3", () => cacheContent3); - Provider.Get("Test4", () => cacheContent4); + AppCache.Get("Test1", () => cacheContent1); + AppCache.Get("Test2", () => cacheContent2); + AppCache.Get("Test3", () => cacheContent3); + AppCache.Get("Test4", () => cacheContent4); Assert.AreEqual(4, GetTotalItemCount); - Provider.Clear("Test1"); - Provider.Clear("Test2"); + AppCache.Clear("Test1"); + AppCache.Clear("Test2"); Assert.AreEqual(2, GetTotalItemCount); } @@ -185,14 +185,14 @@ namespace Umbraco.Tests.Cache var cacheContent2 = new MacroCacheContent(new LiteralControl(), "Test2"); var cacheContent3 = new MacroCacheContent(new LiteralControl(), "Test3"); var cacheContent4 = new LiteralControl(); - Provider.Get("Test1", () => cacheContent1); - Provider.Get("Test2", () => cacheContent2); - Provider.Get("Test3", () => cacheContent3); - Provider.Get("Test4", () => cacheContent4); + AppCache.Get("Test1", () => cacheContent1); + AppCache.Get("Test2", () => cacheContent2); + AppCache.Get("Test3", () => cacheContent3); + AppCache.Get("Test4", () => cacheContent4); Assert.AreEqual(4, GetTotalItemCount); - Provider.Clear(); + AppCache.Clear(); Assert.AreEqual(0, GetTotalItemCount); } @@ -201,7 +201,7 @@ namespace Umbraco.Tests.Cache public void Can_Add_When_Not_Available() { var cacheContent1 = new MacroCacheContent(new LiteralControl(), "Test1"); - Provider.Get("Test1", () => cacheContent1); + AppCache.Get("Test1", () => cacheContent1); Assert.AreEqual(1, GetTotalItemCount); } @@ -209,8 +209,8 @@ namespace Umbraco.Tests.Cache public void Can_Get_When_Available() { var cacheContent1 = new MacroCacheContent(new LiteralControl(), "Test1"); - var result = Provider.Get("Test1", () => cacheContent1); - var result2 = Provider.Get("Test1", () => cacheContent1); + var result = AppCache.Get("Test1", () => cacheContent1); + var result2 = AppCache.Get("Test1", () => cacheContent1); Assert.AreEqual(1, GetTotalItemCount); Assert.AreEqual(result, result2); } @@ -222,15 +222,15 @@ namespace Umbraco.Tests.Cache var cacheContent2 = new MacroCacheContent(new LiteralControl(), "Test2"); var cacheContent3 = new MacroCacheContent(new LiteralControl(), "Test3"); var cacheContent4 = new LiteralControl(); - Provider.Get("Test1", () => cacheContent1); - Provider.Get("Test2", () => cacheContent2); - Provider.Get("Test3", () => cacheContent3); - Provider.Get("Test4", () => cacheContent4); + AppCache.Get("Test1", () => cacheContent1); + AppCache.Get("Test2", () => cacheContent2); + AppCache.Get("Test3", () => cacheContent3); + AppCache.Get("Test4", () => cacheContent4); Assert.AreEqual(4, GetTotalItemCount); //Provider.ClearCacheObjectTypes("umbraco.MacroCacheContent"); - Provider.ClearOfType(typeof(MacroCacheContent).ToString()); + AppCache.ClearOfType(typeof(MacroCacheContent).ToString()); Assert.AreEqual(1, GetTotalItemCount); } @@ -242,14 +242,14 @@ namespace Umbraco.Tests.Cache var cacheContent2 = new MacroCacheContent(new LiteralControl(), "Test2"); var cacheContent3 = new MacroCacheContent(new LiteralControl(), "Test3"); var cacheContent4 = new LiteralControl(); - Provider.Get("Test1", () => cacheContent1); - Provider.Get("Test2", () => cacheContent2); - Provider.Get("Test3", () => cacheContent3); - Provider.Get("Test4", () => cacheContent4); + AppCache.Get("Test1", () => cacheContent1); + AppCache.Get("Test2", () => cacheContent2); + AppCache.Get("Test3", () => cacheContent3); + AppCache.Get("Test4", () => cacheContent4); Assert.AreEqual(4, GetTotalItemCount); - Provider.ClearOfType(); + AppCache.ClearOfType(); Assert.AreEqual(1, GetTotalItemCount); } diff --git a/src/Umbraco.Tests/Cache/DeepCloneRuntimeCacheProviderTests.cs b/src/Umbraco.Tests/Cache/DeepCloneAppCacheTests.cs similarity index 94% rename from src/Umbraco.Tests/Cache/DeepCloneRuntimeCacheProviderTests.cs rename to src/Umbraco.Tests/Cache/DeepCloneAppCacheTests.cs index 7483df1c44..11e2c56873 100644 --- a/src/Umbraco.Tests/Cache/DeepCloneRuntimeCacheProviderTests.cs +++ b/src/Umbraco.Tests/Cache/DeepCloneAppCacheTests.cs @@ -8,13 +8,12 @@ using Umbraco.Core.Cache; using Umbraco.Core.Collections; using Umbraco.Core.Models; using Umbraco.Core.Models.Entities; -using Umbraco.Core.Persistence.Repositories; using Umbraco.Tests.Collections; namespace Umbraco.Tests.Cache { [TestFixture] - public class DeepCloneRuntimeCacheProviderTests : RuntimeCacheProviderTests + public class DeepCloneAppCacheTests : RuntimeAppCacheTests { private DeepCloneAppCache _provider; @@ -29,12 +28,12 @@ namespace Umbraco.Tests.Cache _provider = new DeepCloneAppCache(new WebCachingAppCache(HttpRuntime.Cache)); } - internal override IAppCache Provider + internal override IAppCache AppCache { get { return _provider; } } - internal override IAppPolicyCache RuntimeProvider + internal override IAppPolicyCache AppPolicyCache { get { return _provider; } } diff --git a/src/Umbraco.Tests/Cache/HttpRequestCacheProviderTests.cs b/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs similarity index 82% rename from src/Umbraco.Tests/Cache/HttpRequestCacheProviderTests.cs rename to src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs index f442319d7f..635155f68e 100644 --- a/src/Umbraco.Tests/Cache/HttpRequestCacheProviderTests.cs +++ b/src/Umbraco.Tests/Cache/HttpRequestAppCacheTests.cs @@ -5,7 +5,7 @@ using Umbraco.Tests.TestHelpers; namespace Umbraco.Tests.Cache { [TestFixture] - public class HttpRequestCacheProviderTests : CacheProviderTests + public class HttpRequestAppCacheTests : AppCacheTests { private HttpRequestAppCache _provider; private FakeHttpContextFactory _ctx; @@ -17,7 +17,7 @@ namespace Umbraco.Tests.Cache _provider = new HttpRequestAppCache(_ctx.HttpContext); } - internal override IAppCache Provider + internal override IAppCache AppCache { get { return _provider; } } @@ -29,7 +29,7 @@ namespace Umbraco.Tests.Cache } [TestFixture] - public class StaticCacheProviderTests : CacheProviderTests + public class StaticAppCacheTests : AppCacheTests { private DictionaryCacheProvider _provider; @@ -39,7 +39,7 @@ namespace Umbraco.Tests.Cache _provider = new DictionaryCacheProvider(); } - internal override IAppCache Provider + internal override IAppCache AppCache { get { return _provider; } } diff --git a/src/Umbraco.Tests/Cache/HttpRuntimeCacheProviderTests.cs b/src/Umbraco.Tests/Cache/HttpRuntimeCacheProviderTests.cs deleted file mode 100644 index 6297539a1b..0000000000 --- a/src/Umbraco.Tests/Cache/HttpRuntimeCacheProviderTests.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Diagnostics; -using System.Web; -using NUnit.Framework; -using Umbraco.Core.Cache; - -namespace Umbraco.Tests.Cache -{ - [TestFixture] - public class HttpRuntimeCacheProviderTests : RuntimeCacheProviderTests - { - private WebCachingAppCache _provider; - - protected override int GetTotalItemCount - { - get { return HttpRuntime.Cache.Count; } - } - - public override void Setup() - { - base.Setup(); - _provider = new WebCachingAppCache(HttpRuntime.Cache); - } - - internal override IAppCache Provider - { - get { return _provider; } - } - - internal override IAppPolicyCache RuntimeProvider - { - get { return _provider; } - } - - [Test] - public void DoesNotCacheExceptions() - { - string value; - Assert.Throws(() => { value = (string)_provider.Get("key", () => GetValue(1)); }); - Assert.Throws(() => { value = (string)_provider.Get("key", () => GetValue(2)); }); - - // does not throw - value = (string)_provider.Get("key", () => GetValue(3)); - Assert.AreEqual("succ3", value); - - // cache - value = (string)_provider.Get("key", () => GetValue(4)); - Assert.AreEqual("succ3", value); - } - - private static string GetValue(int i) - { - Debug.Print("get" + i); - if (i < 3) - throw new Exception("fail"); - return "succ" + i; - } - } -} diff --git a/src/Umbraco.Tests/Cache/ObjectCacheProviderTests.cs b/src/Umbraco.Tests/Cache/ObjectAppCacheTests.cs similarity index 78% rename from src/Umbraco.Tests/Cache/ObjectCacheProviderTests.cs rename to src/Umbraco.Tests/Cache/ObjectAppCacheTests.cs index 4d34e81eff..b9c729f891 100644 --- a/src/Umbraco.Tests/Cache/ObjectCacheProviderTests.cs +++ b/src/Umbraco.Tests/Cache/ObjectAppCacheTests.cs @@ -8,7 +8,7 @@ using Umbraco.Core.Cache; namespace Umbraco.Tests.Cache { [TestFixture] - public class ObjectCacheProviderTests : RuntimeCacheProviderTests + public class ObjectAppCacheTests : RuntimeAppCacheTests { private ObjectCacheAppCache _provider; @@ -23,12 +23,12 @@ namespace Umbraco.Tests.Cache _provider = new ObjectCacheAppCache(); } - internal override IAppCache Provider + internal override IAppCache AppCache { get { return _provider; } } - internal override IAppPolicyCache RuntimeProvider + internal override IAppPolicyCache AppPolicyCache { get { return _provider; } } diff --git a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs index 79d0dfb9da..f740637602 100644 --- a/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs +++ b/src/Umbraco.Tests/Cache/PublishedCache/PublishedContentCacheTests.cs @@ -63,12 +63,12 @@ namespace Umbraco.Tests.Cache.PublishedCache _xml = new XmlDocument(); _xml.LoadXml(GetXml()); var xmlStore = new XmlStore(() => _xml, null, null, null); - var cacheProvider = new DictionaryCacheProvider(); + var appCache = new DictionaryCacheProvider(); var domainCache = new DomainCache(ServiceContext.DomainService, DefaultCultureAccessor); var publishedShapshot = new Umbraco.Web.PublishedCache.XmlPublishedCache.PublishedSnapshot( - new PublishedContentCache(xmlStore, domainCache, cacheProvider, globalSettings, new SiteDomainHelper(), ContentTypesCache, null, null), - new PublishedMediaCache(xmlStore, ServiceContext.MediaService, ServiceContext.UserService, cacheProvider, ContentTypesCache, Factory.GetInstance()), - new PublishedMemberCache(null, cacheProvider, Current.Services.MemberService, ContentTypesCache), + new PublishedContentCache(xmlStore, domainCache, appCache, globalSettings, new SiteDomainHelper(), ContentTypesCache, null, null), + new PublishedMediaCache(xmlStore, ServiceContext.MediaService, ServiceContext.UserService, appCache, ContentTypesCache, Factory.GetInstance()), + new PublishedMemberCache(null, appCache, Current.Services.MemberService, ContentTypesCache), domainCache); var publishedSnapshotService = new Mock(); publishedSnapshotService.Setup(x => x.CreatePublishedSnapshot(It.IsAny())).Returns(publishedShapshot); diff --git a/src/Umbraco.Tests/Cache/RuntimeCacheProviderTests.cs b/src/Umbraco.Tests/Cache/RuntimeAppCacheTests.cs similarity index 51% rename from src/Umbraco.Tests/Cache/RuntimeCacheProviderTests.cs rename to src/Umbraco.Tests/Cache/RuntimeAppCacheTests.cs index 6391e4ec7a..1beeae74db 100644 --- a/src/Umbraco.Tests/Cache/RuntimeCacheProviderTests.cs +++ b/src/Umbraco.Tests/Cache/RuntimeAppCacheTests.cs @@ -5,25 +5,23 @@ using Umbraco.Core.Cache; namespace Umbraco.Tests.Cache { - public abstract class RuntimeCacheProviderTests : CacheProviderTests + public abstract class RuntimeAppCacheTests : AppCacheTests { - - internal abstract IAppPolicyCache RuntimeProvider { get; } - + internal abstract IAppPolicyCache AppPolicyCache { get; } [Test] [Explicit("Testing for timeouts cannot work on VSTS.")] public void Can_Add_And_Expire_Struct_Strongly_Typed_With_Null() { var now = DateTime.Now; - RuntimeProvider.Insert("DateTimeTest", () => now, new TimeSpan(0, 0, 0, 0, 200)); - Assert.AreEqual(now, Provider.GetCacheItem("DateTimeTest")); - Assert.AreEqual(now, Provider.GetCacheItem("DateTimeTest")); + AppPolicyCache.Insert("DateTimeTest", () => now, new TimeSpan(0, 0, 0, 0, 200)); + Assert.AreEqual(now, AppCache.GetCacheItem("DateTimeTest")); + Assert.AreEqual(now, AppCache.GetCacheItem("DateTimeTest")); Thread.Sleep(300); //sleep longer than the cache expiration - Assert.AreEqual(default(DateTime), Provider.GetCacheItem("DateTimeTest")); - Assert.AreEqual(null, Provider.GetCacheItem("DateTimeTest")); + Assert.AreEqual(default(DateTime), AppCache.GetCacheItem("DateTimeTest")); + Assert.AreEqual(null, AppCache.GetCacheItem("DateTimeTest")); } } } diff --git a/src/Umbraco.Tests/Cache/WebCachingAppCacheTests.cs b/src/Umbraco.Tests/Cache/WebCachingAppCacheTests.cs new file mode 100644 index 0000000000..e732ae5766 --- /dev/null +++ b/src/Umbraco.Tests/Cache/WebCachingAppCacheTests.cs @@ -0,0 +1,50 @@ +using System; +using System.Diagnostics; +using System.Web; +using NUnit.Framework; +using Umbraco.Core.Cache; + +namespace Umbraco.Tests.Cache +{ + [TestFixture] + public class WebCachingAppCacheTests : RuntimeAppCacheTests + { + private WebCachingAppCache _appCache; + + protected override int GetTotalItemCount => HttpRuntime.Cache.Count; + + public override void Setup() + { + base.Setup(); + _appCache = new WebCachingAppCache(HttpRuntime.Cache); + } + + internal override IAppCache AppCache => _appCache; + + internal override IAppPolicyCache AppPolicyCache => _appCache; + + [Test] + public void DoesNotCacheExceptions() + { + string value; + Assert.Throws(() => { value = (string)_appCache.Get("key", () => GetValue(1)); }); + Assert.Throws(() => { value = (string)_appCache.Get("key", () => GetValue(2)); }); + + // does not throw + value = (string)_appCache.Get("key", () => GetValue(3)); + Assert.AreEqual("succ3", value); + + // cache + value = (string)_appCache.Get("key", () => GetValue(4)); + Assert.AreEqual("succ3", value); + } + + private static string GetValue(int i) + { + Debug.Print("get" + i); + if (i < 3) + throw new Exception("fail"); + return "succ" + i; + } + } +} diff --git a/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs b/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs index 12cd02d2e9..c56ec57db0 100644 --- a/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs @@ -60,7 +60,7 @@ namespace Umbraco.Tests.Scoping { var scopeProvider = ScopeProvider; var service = Current.Services.UserService; - var globalCache = Current.ApplicationCache.IsolatedCaches.GetOrCreate(typeof(IUser)); + var globalCache = Current.AppCaches.IsolatedCaches.GetOrCreate(typeof(IUser)); var user = (IUser)new User("name", "email", "username", "rawPassword"); service.Save(user); @@ -137,7 +137,7 @@ namespace Umbraco.Tests.Scoping { var scopeProvider = ScopeProvider; var service = Current.Services.LocalizationService; - var globalCache = Current.ApplicationCache.IsolatedCaches.GetOrCreate(typeof (ILanguage)); + var globalCache = Current.AppCaches.IsolatedCaches.GetOrCreate(typeof (ILanguage)); var lang = (ILanguage) new Language("fr-FR"); service.Save(lang); @@ -229,7 +229,7 @@ namespace Umbraco.Tests.Scoping { var scopeProvider = ScopeProvider; var service = Current.Services.LocalizationService; - var globalCache = Current.ApplicationCache.IsolatedCaches.GetOrCreate(typeof (IDictionaryItem)); + var globalCache = Current.AppCaches.IsolatedCaches.GetOrCreate(typeof (IDictionaryItem)); var lang = (ILanguage)new Language("fr-FR"); service.Save(lang); diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index e49ba250fa..a2d33a1f31 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -225,7 +225,7 @@ - + @@ -286,11 +286,11 @@ - - - - - + + + + + diff --git a/src/Umbraco.Web/Cache/ContentCacheRefresher.cs b/src/Umbraco.Web/Cache/ContentCacheRefresher.cs index 36397540b6..3f2ef1620c 100644 --- a/src/Umbraco.Web/Cache/ContentCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/ContentCacheRefresher.cs @@ -102,7 +102,7 @@ namespace Umbraco.Web.Cache if (payloads.Any(x => x.ChangeTypes.HasType(TreeChangeTypes.RefreshAll)) || publishedChanged) { // when a public version changes - Current.ApplicationCache.ClearPartialViewCache(); + Current.AppCaches.ClearPartialViewCache(); MacroCacheRefresher.ClearMacroContentCache(AppCaches); // just the content } diff --git a/src/Umbraco.Web/Cache/MediaCacheRefresher.cs b/src/Umbraco.Web/Cache/MediaCacheRefresher.cs index cdaf43dac3..fc62d38e62 100644 --- a/src/Umbraco.Web/Cache/MediaCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/MediaCacheRefresher.cs @@ -47,7 +47,7 @@ namespace Umbraco.Web.Cache if (anythingChanged) { - Current.ApplicationCache.ClearPartialViewCache(); + Current.AppCaches.ClearPartialViewCache(); var mediaCache = AppCaches.IsolatedCaches.Get(); diff --git a/src/Umbraco.Web/Composing/Current.cs b/src/Umbraco.Web/Composing/Current.cs index ed1853c351..8759193964 100644 --- a/src/Umbraco.Web/Composing/Current.cs +++ b/src/Umbraco.Web/Composing/Current.cs @@ -203,7 +203,7 @@ namespace Umbraco.Web.Composing public static IProfilingLogger ProfilingLogger => CoreCurrent.ProfilingLogger; - public static AppCaches ApplicationCache => CoreCurrent.ApplicationCache; + public static AppCaches AppCaches => CoreCurrent.AppCaches; public static ServiceContext Services => CoreCurrent.Services; diff --git a/src/Umbraco.Web/Dictionary/UmbracoCultureDictionary.cs b/src/Umbraco.Web/Dictionary/UmbracoCultureDictionary.cs index 5234bf9fa7..6e1c35352a 100644 --- a/src/Umbraco.Web/Dictionary/UmbracoCultureDictionary.cs +++ b/src/Umbraco.Web/Dictionary/UmbracoCultureDictionary.cs @@ -21,31 +21,29 @@ namespace Umbraco.Web.Dictionary public class DefaultCultureDictionary : Core.Dictionary.ICultureDictionary { private readonly ILocalizationService _localizationService; - private readonly IAppCache _requestCacheProvider; + private readonly IAppCache _requestCache; private readonly CultureInfo _specificCulture; public DefaultCultureDictionary() - : this(Current.Services.LocalizationService, Current.ApplicationCache.RequestCache) - { + : this(Current.Services.LocalizationService, Current.AppCaches.RequestCache) + { } - } - - public DefaultCultureDictionary(ILocalizationService localizationService, IAppCache requestCacheProvider) + public DefaultCultureDictionary(ILocalizationService localizationService, IAppCache requestCache) { _localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService)); - _requestCacheProvider = requestCacheProvider ?? throw new ArgumentNullException(nameof(requestCacheProvider)); + _requestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache)); } public DefaultCultureDictionary(CultureInfo specificCulture) - : this(Current.Services.LocalizationService, Current.ApplicationCache.RequestCache) + : this(Current.Services.LocalizationService, Current.AppCaches.RequestCache) { _specificCulture = specificCulture ?? throw new ArgumentNullException(nameof(specificCulture)); } - public DefaultCultureDictionary(CultureInfo specificCulture, ILocalizationService localizationService, IAppCache requestCacheProvider) + public DefaultCultureDictionary(CultureInfo specificCulture, ILocalizationService localizationService, IAppCache requestCache) { _localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService)); - _requestCacheProvider = requestCacheProvider ?? throw new ArgumentNullException(nameof(requestCacheProvider)); + _requestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache)); _specificCulture = specificCulture ?? throw new ArgumentNullException(nameof(specificCulture)); } @@ -123,7 +121,7 @@ namespace Umbraco.Web.Dictionary { //ensure it's stored/retrieved from request cache //NOTE: This is no longer necessary since these are cached at the runtime level, but we can leave it here for now. - return _requestCacheProvider.GetCacheItem(typeof (DefaultCultureDictionary).Name + "Culture" + Culture.Name, + return _requestCache.GetCacheItem(typeof (DefaultCultureDictionary).Name + "Culture" + Culture.Name, () => _localizationService.GetLanguageByIsoCode(Culture.Name)); } } diff --git a/src/Umbraco.Web/Editors/CurrentUserController.cs b/src/Umbraco.Web/Editors/CurrentUserController.cs index b0f4af0f57..02470e8ea1 100644 --- a/src/Umbraco.Web/Editors/CurrentUserController.cs +++ b/src/Umbraco.Web/Editors/CurrentUserController.cs @@ -157,7 +157,7 @@ namespace Umbraco.Web.Editors public async Task PostSetAvatar() { //borrow the logic from the user controller - return await UsersController.PostSetAvatarInternal(Request, Services.UserService, Current.ApplicationCache.StaticCache, Security.GetUserId().ResultOr(0)); + return await UsersController.PostSetAvatarInternal(Request, Services.UserService, Current.AppCaches.StaticCache, Security.GetUserId().ResultOr(0)); } /// diff --git a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs index 9c30f74ea7..626a19a369 100644 --- a/src/Umbraco.Web/HtmlHelperRenderExtensions.cs +++ b/src/Umbraco.Web/HtmlHelperRenderExtensions.cs @@ -105,7 +105,7 @@ namespace Umbraco.Web var contextualKey = contextualKeyBuilder(model, viewData); cacheKey.AppendFormat("c{0}-", contextualKey); } - return Current.ApplicationCache.CachedPartialView(htmlHelper, partialViewName, model, cachedSeconds, cacheKey.ToString(), viewData); + return Current.AppCaches.CachedPartialView(htmlHelper, partialViewName, model, cachedSeconds, cacheKey.ToString(), viewData); } public static MvcHtmlString EditorFor(this HtmlHelper htmlHelper, string templateName = "", string htmlFieldName = "", object additionalViewData = null) diff --git a/src/Umbraco.Web/Macros/MacroRenderer.cs b/src/Umbraco.Web/Macros/MacroRenderer.cs index 0bcdb3225b..b7187da743 100755 --- a/src/Umbraco.Web/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web/Macros/MacroRenderer.cs @@ -94,7 +94,7 @@ namespace Umbraco.Web.Macros // only if cache is enabled if (UmbracoContext.Current.InPreviewMode || model.CacheDuration <= 0) return null; - var cache = Current.ApplicationCache.RuntimeCache; + var cache = Current.AppCaches.RuntimeCache; var macroContent = cache.GetCacheItem(CacheKeys.MacroContentCacheKey + model.CacheIdentifier); if (macroContent == null) return null; @@ -151,7 +151,7 @@ namespace Umbraco.Web.Macros // remember when we cache the content macroContent.Date = DateTime.Now; - var cache = Current.ApplicationCache.RuntimeCache; + var cache = Current.AppCaches.RuntimeCache; cache.Insert( CacheKeys.MacroContentCacheKey + model.CacheIdentifier, () => macroContent, diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/DictionaryPublishedContent.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/DictionaryPublishedContent.cs index e040e7e926..83bd84dab6 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/DictionaryPublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/DictionaryPublishedContent.cs @@ -35,7 +35,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache Func getParent, Func> getChildren, Func getProperty, - IAppCache cacheProvider, + IAppCache appCache, PublishedContentTypeCache contentTypeCache, XPathNavigator nav, bool fromExamine) @@ -47,7 +47,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache _getParent = new Lazy(() => getParent(ParentId)); _getChildren = new Lazy>(() => getChildren(Id, nav)); _getProperty = getProperty; - _cacheProvider = cacheProvider; + _appCache = appCache; LoadedFromExamine = fromExamine; @@ -133,7 +133,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache //private readonly Func> _getChildren; private readonly Lazy> _getChildren; private readonly Func _getProperty; - private readonly IAppCache _cacheProvider; + private readonly IAppCache _appCache; /// /// Returns 'Media' as the item type diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs index 67813ce9f6..d8c7c41ea1 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedContentCache.cs @@ -15,7 +15,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache { internal class PublishedContentCache : PublishedCacheBase, IPublishedContentCache { - private readonly IAppCache _cacheProvider; + private readonly IAppCache _appCache; private readonly IGlobalSettings _globalSettings; private readonly RoutesCache _routesCache; private readonly IDomainCache _domainCache; @@ -24,13 +24,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache // initialize a PublishedContentCache instance with // an XmlStore containing the master xml - // an ICacheProvider that should be at request-level + // an IAppCache that should be at request-level // a RoutesCache - need to cleanup that one // a preview token string (or null if not previewing) public PublishedContentCache( XmlStore xmlStore, // an XmlStore containing the master xml IDomainCache domainCache, // an IDomainCache implementation - IAppCache cacheProvider, // an ICacheProvider that should be at request-level + IAppCache appCache, // an IAppCache that should be at request-level IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper, PublishedContentTypeCache contentTypeCache, // a PublishedContentType cache @@ -38,7 +38,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache string previewToken) // a preview token string (or null if not previewing) : base(previewToken.IsNullOrWhiteSpace() == false) { - _cacheProvider = cacheProvider; + _appCache = appCache; _globalSettings = globalSettings; _routesCache = routesCache; // may be null for unit-testing _contentTypeCache = contentTypeCache; @@ -315,13 +315,13 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache private IPublishedContent ConvertToDocument(XmlNode xmlNode, bool isPreviewing) { - return xmlNode == null ? null : XmlPublishedContent.Get(xmlNode, isPreviewing, _cacheProvider, _contentTypeCache); + return xmlNode == null ? null : XmlPublishedContent.Get(xmlNode, isPreviewing, _appCache, _contentTypeCache); } private IEnumerable ConvertToDocuments(XmlNodeList xmlNodes, bool isPreviewing) { return xmlNodes.Cast() - .Select(xmlNode => XmlPublishedContent.Get(xmlNode, isPreviewing, _cacheProvider, _contentTypeCache)); + .Select(xmlNode => XmlPublishedContent.Get(xmlNode, isPreviewing, _appCache, _contentTypeCache)); } #endregion @@ -517,8 +517,8 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache // clear recursive properties cached by XmlPublishedContent.GetProperty // assume that nothing else is going to cache IPublishedProperty items (else would need to do ByKeySearch) // NOTE also clears all the media cache properties, which is OK (see media cache) - _cacheProvider.ClearOfType(); - //_cacheProvider.ClearCacheByKeySearch("XmlPublishedCache.PublishedContentCache:RecursiveProperty-"); + _appCache.ClearOfType(); + //_appCache.ClearCacheByKeySearch("XmlPublishedCache.PublishedContentCache:RecursiveProperty-"); } #endregion diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs index 3ead5a5166..dadf40a33b 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs @@ -43,15 +43,15 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache private readonly IEntityXmlSerializer _entitySerializer; // must be specified by the ctor - private readonly IAppCache _cacheProvider; + private readonly IAppCache _appCache; - public PublishedMediaCache(XmlStore xmlStore, IMediaService mediaService, IUserService userService, IAppCache cacheProvider, PublishedContentTypeCache contentTypeCache, IEntityXmlSerializer entitySerializer) + public PublishedMediaCache(XmlStore xmlStore, IMediaService mediaService, IUserService userService, IAppCache appCache, PublishedContentTypeCache contentTypeCache, IEntityXmlSerializer entitySerializer) : base(false) { _mediaService = mediaService ?? throw new ArgumentNullException(nameof(mediaService)); _userService = userService ?? throw new ArgumentNullException(nameof(userService)); - _cacheProvider = cacheProvider; + _appCache = appCache; _xmlStore = xmlStore; _contentTypeCache = contentTypeCache; _entitySerializer = entitySerializer; @@ -63,16 +63,16 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache /// /// /// - /// + /// /// /// - internal PublishedMediaCache(IMediaService mediaService, IUserService userService, ISearcher searchProvider, IAppCache cacheProvider, PublishedContentTypeCache contentTypeCache, IEntityXmlSerializer entitySerializer) + internal PublishedMediaCache(IMediaService mediaService, IUserService userService, ISearcher searchProvider, IAppCache appCache, PublishedContentTypeCache contentTypeCache, IEntityXmlSerializer entitySerializer) : base(false) { _mediaService = mediaService ?? throw new ArgumentNullException(nameof(mediaService)); _userService = userService ?? throw new ArgumentNullException(nameof(userService)); _searchProvider = searchProvider ?? throw new ArgumentNullException(nameof(searchProvider)); - _cacheProvider = cacheProvider; + _appCache = appCache; _contentTypeCache = contentTypeCache; _entitySerializer = entitySerializer; } @@ -598,8 +598,8 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache // clear recursive properties cached by XmlPublishedContent.GetProperty // assume that nothing else is going to cache IPublishedProperty items (else would need to do ByKeySearch) // NOTE all properties cleared when clearing the content cache (see content cache) - //_cacheProvider.ClearCacheObjectTypes(); - //_cacheProvider.ClearCacheByKeySearch("XmlPublishedCache.PublishedMediaCache:RecursiveProperty-"); + //_appCache.ClearCacheObjectTypes(); + //_appCache.ClearCacheByKeySearch("XmlPublishedCache.PublishedMediaCache:RecursiveProperty-"); } #region Content types @@ -663,7 +663,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache parentId => parentId < 0 ? null : GetUmbracoMedia(parentId), GetChildrenMedia, GetProperty, - _cacheProvider, + _appCache, _contentTypeCache, cacheValues.XPath, // though, outside of tests, that should be null cacheValues.FromExamine @@ -676,14 +676,14 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache if (_publishedMediaCacheEnabled == false) return func(id); - var cache = Current.ApplicationCache.RuntimeCache; + var cache = Current.AppCaches.RuntimeCache; var key = PublishedMediaCacheKey + id; return (CacheValues)cache.Get(key, () => func(id), _publishedMediaCacheTimespan); } internal static void ClearCache(int id) { - var cache = Current.ApplicationCache.RuntimeCache; + var cache = Current.AppCaches.RuntimeCache; var sid = id.ToString(); var key = PublishedMediaCacheKey + sid; diff --git a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs index a313d6947d..eb54c85984 100644 --- a/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs +++ b/src/Umbraco.Web/PublishedCache/XmlPublishedCache/XmlPublishedContent.cs @@ -20,18 +20,18 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache [XmlType(Namespace = "http://umbraco.org/webservices/")] internal class XmlPublishedContent : PublishedContentBase { - private XmlPublishedContent(XmlNode xmlNode, bool isPreviewing, IAppCache cacheProvider, PublishedContentTypeCache contentTypeCache) + private XmlPublishedContent(XmlNode xmlNode, bool isPreviewing, IAppCache appCache, PublishedContentTypeCache contentTypeCache) { _xmlNode = xmlNode; _isPreviewing = isPreviewing; - _cacheProvider = cacheProvider; + _appCache = appCache; _contentTypeCache = contentTypeCache; } private readonly XmlNode _xmlNode; private readonly bool _isPreviewing; - private readonly IAppCache _cacheProvider; // at snapshot/request level (see PublishedContentCache) + private readonly IAppCache _appCache; // at snapshot/request level (see PublishedContentCache) private readonly PublishedContentTypeCache _contentTypeCache; private readonly object _initializeLock = new object(); @@ -252,7 +252,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache if (parent == null) return; if (parent.Attributes?.GetNamedItem("isDoc") != null) - _parent = Get(parent, _isPreviewing, _cacheProvider, _contentTypeCache); + _parent = Get(parent, _isPreviewing, _appCache, _contentTypeCache); _parentInitialized = true; } @@ -409,7 +409,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache var iterator = nav.Select(expr); _children = iterator.Cast() - .Select(n => Get(((IHasXmlNode) n).GetNode(), _isPreviewing, _cacheProvider, _contentTypeCache)) + .Select(n => Get(((IHasXmlNode) n).GetNode(), _isPreviewing, _appCache, _contentTypeCache)) .OrderBy(x => x.SortOrder) .ToList(); @@ -440,7 +440,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache public static void ClearRequest() { - Current.ApplicationCache.RequestCache.ClearByKey(CacheKeyPrefix); + Current.AppCaches.RequestCache.ClearByKey(CacheKeyPrefix); } private const string CacheKeyPrefix = "CONTENTCACHE_XMLPUBLISHEDCONTENT_";