From 1506d8c3fa4f51978422d9f9a8460ae15ce2a0d5 Mon Sep 17 00:00:00 2001 From: Stephan Date: Fri, 18 Jan 2019 15:49:54 +0100 Subject: [PATCH] Kill AppCaches.StaticCache --- src/Umbraco.Core/Cache/AppCaches.cs | 17 ++--------------- src/Umbraco.Core/Models/UserExtensions.cs | 6 +++--- src/Umbraco.Core/Runtime/CoreRuntime.cs | 1 - src/Umbraco.Tests/Macros/MacroTests.cs | 1 - .../Repositories/DocumentRepositoryTest.cs | 1 - .../Repositories/MediaRepositoryTest.cs | 1 - .../Scoping/ScopedRepositoryTests.cs | 1 - .../Editors/CurrentUserController.cs | 2 +- src/Umbraco.Web/Editors/UsersController.cs | 10 +++++----- src/Umbraco.Web/Runtime/WebRuntime.cs | 1 - 10 files changed, 11 insertions(+), 30 deletions(-) diff --git a/src/Umbraco.Core/Cache/AppCaches.cs b/src/Umbraco.Core/Cache/AppCaches.cs index d81e79f7d8..e8bc49605a 100644 --- a/src/Umbraco.Core/Cache/AppCaches.cs +++ b/src/Umbraco.Core/Cache/AppCaches.cs @@ -21,7 +21,6 @@ namespace Umbraco.Core.Cache public AppCaches(System.Web.Caching.Cache cache) : this( new WebCachingAppCache(cache), - new DictionaryAppCache(), new HttpRequestAppCache(), new IsolatedCaches(t => new ObjectCacheAppCache())) { } @@ -31,12 +30,10 @@ namespace Umbraco.Core.Cache /// public AppCaches( IAppPolicyCache runtimeCache, - IAppCache staticCache, IAppCache requestCache, IsolatedCaches isolatedCaches) { RuntimeCache = runtimeCache ?? throw new ArgumentNullException(nameof(runtimeCache)); - StaticCache = staticCache ?? throw new ArgumentNullException(nameof(staticCache)); RequestCache = requestCache ?? throw new ArgumentNullException(nameof(requestCache)); IsolatedCaches = isolatedCaches ?? throw new ArgumentNullException(nameof(isolatedCaches)); } @@ -48,7 +45,7 @@ namespace Umbraco.Core.Cache /// When used by repositories, all cache policies apply, but the underlying caches do not cache anything. /// Used by tests. /// - public static AppCaches Disabled { get; } = new AppCaches(NoAppCache.Instance, NoAppCache.Instance, NoAppCache.Instance, new IsolatedCaches(_ => NoAppCache.Instance)); + public static AppCaches Disabled { get; } = new AppCaches(NoAppCache.Instance, NoAppCache.Instance, new IsolatedCaches(_ => NoAppCache.Instance)); /// /// Gets the special no-cache instance. @@ -57,7 +54,7 @@ namespace Umbraco.Core.Cache /// When used by repositories, all cache policies are bypassed. /// Used by repositories that do no cache. /// - public static AppCaches NoCache { get; } = new AppCaches(NoAppCache.Instance, NoAppCache.Instance, NoAppCache.Instance, new IsolatedCaches(_ => NoAppCache.Instance)); + public static AppCaches NoCache { get; } = new AppCaches(NoAppCache.Instance, NoAppCache.Instance, new IsolatedCaches(_ => NoAppCache.Instance)); /// /// Gets the per-request cache. @@ -68,14 +65,6 @@ namespace Umbraco.Core.Cache /// public IAppCache RequestCache { get; } - /// - /// Returns the current Runtime cache - /// - /// - /// fixme - what is this? why not use RuntimeCache? - /// - public IAppCache StaticCache { get; } - /// /// Gets the runtime cache. /// @@ -93,7 +82,5 @@ namespace Umbraco.Core.Cache /// search through all keys on a global scale. /// public IsolatedCaches IsolatedCaches { get; } - } - } diff --git a/src/Umbraco.Core/Models/UserExtensions.cs b/src/Umbraco.Core/Models/UserExtensions.cs index 7db3e3adbe..19726cc5a5 100644 --- a/src/Umbraco.Core/Models/UserExtensions.cs +++ b/src/Umbraco.Core/Models/UserExtensions.cs @@ -50,11 +50,11 @@ namespace Umbraco.Core.Models /// Tries to lookup the user's gravatar to see if the endpoint can be reached, if so it returns the valid URL /// /// - /// + /// /// /// A list of 5 different sized avatar URLs /// - internal static string[] GetUserAvatarUrls(this IUser user, IAppCache staticCache) + internal static string[] GetUserAvatarUrls(this IUser user, IAppCache cache) { // If FIPS is required, never check the Gravatar service as it only supports MD5 hashing. // Unfortunately, if the FIPS setting is enabled on Windows, using MD5 will throw an exception @@ -71,7 +71,7 @@ namespace Umbraco.Core.Models var gravatarUrl = "https://www.gravatar.com/avatar/" + gravatarHash + "?d=404"; //try gravatar - var gravatarAccess = staticCache.GetCacheItem("UserAvatar" + user.Id, () => + var gravatarAccess = cache.GetCacheItem("UserAvatar" + user.Id, () => { // Test if we can reach this URL, will fail when there's network or firewall errors var request = (HttpWebRequest)WebRequest.Create(gravatarUrl); diff --git a/src/Umbraco.Core/Runtime/CoreRuntime.cs b/src/Umbraco.Core/Runtime/CoreRuntime.cs index 8f1fa54a0c..6918c9b423 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntime.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntime.cs @@ -332,7 +332,6 @@ namespace Umbraco.Core.Runtime return new AppCaches( new DeepCloneAppCache(new ObjectCacheAppCache()), - new DictionaryAppCache(), NoAppCache.Instance, new IsolatedCaches(type => new DeepCloneAppCache(new ObjectCacheAppCache()))); } diff --git a/src/Umbraco.Tests/Macros/MacroTests.cs b/src/Umbraco.Tests/Macros/MacroTests.cs index 15549d5d46..0d60181c79 100644 --- a/src/Umbraco.Tests/Macros/MacroTests.cs +++ b/src/Umbraco.Tests/Macros/MacroTests.cs @@ -23,7 +23,6 @@ namespace Umbraco.Tests.Macros //we DO want cache enabled for these tests var cacheHelper = new AppCaches( new ObjectCacheAppCache(), - new DictionaryAppCache(), NoAppCache.Instance, new IsolatedCaches(type => new ObjectCacheAppCache())); //Current.ApplicationContext = new ApplicationContext(cacheHelper, new ProfilingLogger(Mock.Of(), Mock.Of())); diff --git a/src/Umbraco.Tests/Persistence/Repositories/DocumentRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/DocumentRepositoryTest.cs index c4bd053d7f..bb2d981b07 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/DocumentRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/DocumentRepositoryTest.cs @@ -78,7 +78,6 @@ namespace Umbraco.Tests.Persistence.Repositories var realCache = new AppCaches( new ObjectCacheAppCache(), new DictionaryAppCache(), - new DictionaryAppCache(), new IsolatedCaches(t => new ObjectCacheAppCache())); var provider = TestObjects.GetScopeProvider(Logger); diff --git a/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs index 5635def412..eaf0425edf 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/MediaRepositoryTest.cs @@ -49,7 +49,6 @@ namespace Umbraco.Tests.Persistence.Repositories var realCache = new AppCaches( new ObjectCacheAppCache(), new DictionaryAppCache(), - new DictionaryAppCache(), new IsolatedCaches(t => new ObjectCacheAppCache())); var provider = TestObjects.GetScopeProvider(Logger); diff --git a/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs b/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs index 99d2fbd222..dee7a99ad0 100644 --- a/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedRepositoryTests.cs @@ -42,7 +42,6 @@ namespace Umbraco.Tests.Scoping // this is what's created core web runtime return new AppCaches( new DeepCloneAppCache(new ObjectCacheAppCache()), - new DictionaryAppCache(), NoAppCache.Instance, new IsolatedCaches(type => new DeepCloneAppCache(new ObjectCacheAppCache()))); } diff --git a/src/Umbraco.Web/Editors/CurrentUserController.cs b/src/Umbraco.Web/Editors/CurrentUserController.cs index 02470e8ea1..f759a9e604 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.AppCaches.StaticCache, Security.GetUserId().ResultOr(0)); + return await UsersController.PostSetAvatarInternal(Request, Services.UserService, AppCaches.RuntimeCache, Security.GetUserId().ResultOr(0)); } /// diff --git a/src/Umbraco.Web/Editors/UsersController.cs b/src/Umbraco.Web/Editors/UsersController.cs index 70ab8c946a..36a8bf1158 100644 --- a/src/Umbraco.Web/Editors/UsersController.cs +++ b/src/Umbraco.Web/Editors/UsersController.cs @@ -49,7 +49,7 @@ namespace Umbraco.Web.Editors /// public string[] GetCurrentUserAvatarUrls() { - var urls = UmbracoContext.Security.CurrentUser.GetUserAvatarUrls(AppCaches.StaticCache); + var urls = UmbracoContext.Security.CurrentUser.GetUserAvatarUrls(AppCaches.RuntimeCache); if (urls == null) throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not access Gravatar endpoint")); @@ -60,10 +60,10 @@ namespace Umbraco.Web.Editors [FileUploadCleanupFilter(false)] public async Task PostSetAvatar(int id) { - return await PostSetAvatarInternal(Request, Services.UserService, AppCaches.StaticCache, id); + return await PostSetAvatarInternal(Request, Services.UserService, AppCaches.RuntimeCache, id); } - internal static async Task PostSetAvatarInternal(HttpRequestMessage request, IUserService userService, IAppCache staticCache, int id) + internal static async Task PostSetAvatarInternal(HttpRequestMessage request, IUserService userService, IAppCache cache, int id) { if (request.Content.IsMimeMultipartContent() == false) { @@ -117,7 +117,7 @@ namespace Umbraco.Web.Editors }); } - return request.CreateResponse(HttpStatusCode.OK, user.GetUserAvatarUrls(staticCache)); + return request.CreateResponse(HttpStatusCode.OK, user.GetUserAvatarUrls(cache)); } [AppendUserModifiedHeader("id")] @@ -150,7 +150,7 @@ namespace Umbraco.Web.Editors Current.MediaFileSystem.DeleteFile(filePath); } - return Request.CreateResponse(HttpStatusCode.OK, found.GetUserAvatarUrls(AppCaches.StaticCache)); + return Request.CreateResponse(HttpStatusCode.OK, found.GetUserAvatarUrls(AppCaches.RuntimeCache)); } /// diff --git a/src/Umbraco.Web/Runtime/WebRuntime.cs b/src/Umbraco.Web/Runtime/WebRuntime.cs index 90da402849..0f689378d6 100644 --- a/src/Umbraco.Web/Runtime/WebRuntime.cs +++ b/src/Umbraco.Web/Runtime/WebRuntime.cs @@ -63,7 +63,6 @@ namespace Umbraco.Web.Runtime // we need to have the dep clone runtime cache provider to ensure // all entities are cached properly (cloned in and cloned out) new DeepCloneAppCache(new WebCachingAppCache(HttpRuntime.Cache)), - new DictionaryAppCache(), // we need request based cache when running in web-based context new HttpRequestAppCache(), new IsolatedCaches(type =>