Make ValueEditorCacheRefresher a distributed cache refresher
This commit is contained in:
@@ -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<DataTypeSavedNotification>,
|
||||
INotificationHandler<DataTypeDeletedNotification>
|
||||
public sealed class ValueEditorCacheRefresher : PayloadCacheRefresherBase<DataTypeCacheRefresherNotification, DataTypeCacheRefresher.JsonPayload>
|
||||
{
|
||||
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<int> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,9 +256,6 @@ namespace Umbraco.Cms.Core.DependencyInjection
|
||||
|
||||
// Register ValueEditorCache used for validation
|
||||
Services.AddSingleton<IValueEditorCache, ValueEditorCache>();
|
||||
Services
|
||||
.AddNotificationHandler<DataTypeSavedNotification, ValueEditorCacheRefresher>()
|
||||
.AddNotificationHandler<DataTypeDeletedNotification, ValueEditorCacheRefresher>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<IDataType> 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)
|
||||
|
||||
Reference in New Issue
Block a user