Create separate refresher for ValueEditorCache
Notification handlers are scoped.
This commit is contained in:
@@ -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<int> dataTypeIds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<DataTypeSavedNotification>,
|
||||
INotificationHandler<DataTypeDeletedNotification>
|
||||
public class ValueEditorCache : IValueEditorCache
|
||||
{
|
||||
private readonly Dictionary<string, Dictionary<int, IDataValueEditor>> _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<int> dataTypeIds)
|
||||
public void ClearCache(IEnumerable<int> dataTypeIds)
|
||||
{
|
||||
lock (_dictionaryLocker)
|
||||
{
|
||||
|
||||
21
src/Umbraco.Core/Cache/ValueEditorCacheRefresher.cs
Normal file
21
src/Umbraco.Core/Cache/ValueEditorCacheRefresher.cs
Normal file
@@ -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<DataTypeSavedNotification>,
|
||||
INotificationHandler<DataTypeDeletedNotification>
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user