From 65b69dfa4af1417510e3f34eb84a28a5cf888ce2 Mon Sep 17 00:00:00 2001 From: Nikolaj Date: Tue, 24 Aug 2021 11:02:37 +0200 Subject: [PATCH] Create separate refresher for ValueEditorCache Notification handlers are scoped. --- src/Umbraco.Core/Cache/IValueEditorCache.cs | 4 +++- src/Umbraco.Core/Cache/ValueEditorCache.cs | 15 ++----------- .../Cache/ValueEditorCacheRefresher.cs | 21 +++++++++++++++++++ .../DependencyInjection/UmbracoBuilder.cs | 4 ++-- 4 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 src/Umbraco.Core/Cache/ValueEditorCacheRefresher.cs diff --git a/src/Umbraco.Core/Cache/IValueEditorCache.cs b/src/Umbraco.Core/Cache/IValueEditorCache.cs index 72b85746c4..f283d730b5 100644 --- a/src/Umbraco.Core/Cache/IValueEditorCache.cs +++ b/src/Umbraco.Core/Cache/IValueEditorCache.cs @@ -1,4 +1,5 @@ -using Umbraco.Cms.Core.Models; +using System.Collections.Generic; +using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.PropertyEditors; namespace Umbraco.Cms.Core.Cache @@ -6,5 +7,6 @@ namespace Umbraco.Cms.Core.Cache public interface IValueEditorCache { public IDataValueEditor GetValueEditor(IDataEditor dataEditor, IDataType dataType); + public void ClearCache(IEnumerable dataTypeIds); } } diff --git a/src/Umbraco.Core/Cache/ValueEditorCache.cs b/src/Umbraco.Core/Cache/ValueEditorCache.cs index 44a813f129..44aa83d44d 100644 --- a/src/Umbraco.Core/Cache/ValueEditorCache.cs +++ b/src/Umbraco.Core/Cache/ValueEditorCache.cs @@ -1,15 +1,10 @@ using System.Collections.Generic; -using System.Linq; -using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Notifications; using Umbraco.Cms.Core.PropertyEditors; namespace Umbraco.Cms.Core.Cache { - public class ValueEditorCache : IValueEditorCache, - INotificationHandler, - INotificationHandler + public class ValueEditorCache : IValueEditorCache { private readonly Dictionary> _valueEditorCache; private readonly object _dictionaryLocker; @@ -47,13 +42,7 @@ namespace Umbraco.Cms.Core.Cache } } - public void Handle(DataTypeSavedNotification notification) => - ClearCache(notification.SavedEntities.Select(x => x.Id)); - - public void Handle(DataTypeDeletedNotification notification) => - ClearCache(notification.DeletedEntities.Select(x => x.Id)); - - private void ClearCache(IEnumerable dataTypeIds) + public void ClearCache(IEnumerable dataTypeIds) { lock (_dictionaryLocker) { diff --git a/src/Umbraco.Core/Cache/ValueEditorCacheRefresher.cs b/src/Umbraco.Core/Cache/ValueEditorCacheRefresher.cs new file mode 100644 index 0000000000..04330a1973 --- /dev/null +++ b/src/Umbraco.Core/Cache/ValueEditorCacheRefresher.cs @@ -0,0 +1,21 @@ +using System.Linq; +using Umbraco.Cms.Core.Events; +using Umbraco.Cms.Core.Notifications; + +namespace Umbraco.Cms.Core.Cache +{ + public class ValueEditorCacheRefresher : + INotificationHandler, + INotificationHandler + { + private readonly IValueEditorCache _valueEditorCache; + + public ValueEditorCacheRefresher(IValueEditorCache valueEditorCache) => _valueEditorCache = valueEditorCache; + + public void Handle(DataTypeSavedNotification notification) => + _valueEditorCache.ClearCache(notification.SavedEntities.Select(x => x.Id)); + + public void Handle(DataTypeDeletedNotification notification) => + _valueEditorCache.ClearCache(notification.DeletedEntities.Select(x => x.Id)); + } +} diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs index 35239121c0..3212787fdb 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs @@ -257,8 +257,8 @@ namespace Umbraco.Cms.Core.DependencyInjection // Register ValueEditorCache used for validation Services.AddSingleton(); Services - .AddNotificationHandler() - .AddNotificationHandler(); + .AddNotificationHandler() + .AddNotificationHandler(); } } }