diff --git a/src/Umbraco.Core/Cache/ValueEditorCacheRefresher.cs b/src/Umbraco.Core/Cache/ValueEditorCacheRefresher.cs index 04330a1973..c815ca7a71 100644 --- a/src/Umbraco.Core/Cache/ValueEditorCacheRefresher.cs +++ b/src/Umbraco.Core/Cache/ValueEditorCacheRefresher.cs @@ -1,21 +1,57 @@ -using System.Linq; +using System; +using System.Collections.Generic; +using System.Linq; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Notifications; +using Umbraco.Cms.Core.Serialization; namespace Umbraco.Cms.Core.Cache { - public class ValueEditorCacheRefresher : - INotificationHandler, - INotificationHandler + public sealed class ValueEditorCacheRefresher : PayloadCacheRefresherBase { private readonly IValueEditorCache _valueEditorCache; - public ValueEditorCacheRefresher(IValueEditorCache valueEditorCache) => _valueEditorCache = valueEditorCache; + public ValueEditorCacheRefresher( + AppCaches appCaches, + IJsonSerializer serializer, + IEventAggregator eventAggregator, + ICacheRefresherNotificationFactory factory, + IValueEditorCache valueEditorCache) : base(appCaches, serializer, eventAggregator, factory) + { + _valueEditorCache = valueEditorCache; + } - public void Handle(DataTypeSavedNotification notification) => - _valueEditorCache.ClearCache(notification.SavedEntities.Select(x => x.Id)); + public static readonly Guid UniqueId = Guid.Parse("D28A1DBB-2308-4918-9A92-2F8689B6CBFE"); + public override Guid RefresherUniqueId => UniqueId; + public override string Name => "ValueEditorCacheRefresher"; - public void Handle(DataTypeDeletedNotification notification) => - _valueEditorCache.ClearCache(notification.DeletedEntities.Select(x => x.Id)); + public override void Refresh(DataTypeCacheRefresher.JsonPayload[] payloads) + { + IEnumerable ids = payloads.Select(x => x.Id); + _valueEditorCache.ClearCache(ids); + } + + // these events should never trigger + // everything should be PAYLOAD/JSON + + public override void RefreshAll() + { + throw new NotSupportedException(); + } + + public override void Refresh(int id) + { + throw new NotSupportedException(); + } + + public override void Refresh(Guid id) + { + throw new NotSupportedException(); + } + + public override void Remove(int id) + { + throw new NotSupportedException(); + } } } diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs index 3212787fdb..6f6a53df66 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs @@ -256,9 +256,6 @@ namespace Umbraco.Cms.Core.DependencyInjection // Register ValueEditorCache used for validation Services.AddSingleton(); - Services - .AddNotificationHandler() - .AddNotificationHandler(); } } } diff --git a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs index 35845f3cd0..6e6f549b03 100644 --- a/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs +++ b/src/Umbraco.Infrastructure/Cache/DistributedCacheBinder_Handlers.cs @@ -130,6 +130,7 @@ namespace Umbraco.Cms.Core.Cache { _distributedCache.RefreshDataTypeCache(entity); } + _distributedCache.RefreshValueEditorCache(notification.SavedEntities); } public void Handle(DataTypeDeletedNotification notification) @@ -138,6 +139,7 @@ namespace Umbraco.Cms.Core.Cache { _distributedCache.RemoveDataTypeCache(entity); } + _distributedCache.RefreshValueEditorCache(notification.DeletedEntities); } #endregion diff --git a/src/Umbraco.Infrastructure/Cache/DistributedCacheExtensions.cs b/src/Umbraco.Infrastructure/Cache/DistributedCacheExtensions.cs index a0ba0ff128..ceac767a8c 100644 --- a/src/Umbraco.Infrastructure/Cache/DistributedCacheExtensions.cs +++ b/src/Umbraco.Infrastructure/Cache/DistributedCacheExtensions.cs @@ -1,6 +1,7 @@ // Copyright (c) Umbraco. // See LICENSE for more details. +using System.Collections.Generic; using System.Linq; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; @@ -106,6 +107,21 @@ namespace Umbraco.Extensions #endregion + #region ValueEditorCache + + public static void RefreshValueEditorCache(this DistributedCache dc, IEnumerable dataTypes) + { + if (dataTypes is null) + { + return; + } + + var payloads = dataTypes.Select(x => new DataTypeCacheRefresher.JsonPayload(x.Id, x.Key, false)); + dc.RefreshByPayload(ValueEditorCacheRefresher.UniqueId, payloads); + } + + #endregion + #region ContentCache public static void RefreshAllContentCache(this DistributedCache dc)