Files
Umbraco-CMS/src/Umbraco.Core/Cache/Refreshers/PayloadCacheRefresherBase.cs
Ronald Barendse c989c5e214 Support publishing multiple notifications, filter on handler type and add IDistributedCacheNotificationHandler<TNotification> (optimizes cache refreshers) (#14332)
* Clean up DistributedCache and add additional checks

* Add IEnumerable overloads to DistributedCacheExtensions

* Update handlers to use new IEnumerable overloads

* Move DistributedCacheExtensions to Core

* Restructure cache refreshers into folders

* Add IDistributedCacheNotificationHandler

* Rewrite DistributedCacheBinder into seperate IDistributedCacheNotificationHandler implementations

* Obsolete DistributedCacheBinder and use new IDistributedCacheHandler implementations

* Clean up ServerMessengerBase

* Ensure cache refreshers only process distinct values

* Add support for publishing multiple notifications and filter on handler type

* Suppress compatibility issues

* Remove DistributedCacheBinder and suppress compatibility issues

* Add ScopedNotificationPublisher<TNotificationHandler>

* Improve notification type lookup/enumeration

* Ensure INotificationAsyncHandler handles multiple notitications sequentially

* Minimize cache instruction JSON

* Chunk notifications by type to keep publish order

* Only serialize required RefreshInstruction properties
2023-06-20 11:15:47 +02:00

51 lines
1.8 KiB
C#

using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Serialization;
using Umbraco.Cms.Core.Sync;
namespace Umbraco.Cms.Core.Cache;
/// <summary>
/// A base class for "payload" class refreshers.
/// </summary>
/// <typeparam name="TPayload">The payload type.</typeparam>
/// <typeparam name="TNotification">The notification type</typeparam>
/// <remarks>The actual cache refresher type is used for strongly typed events.</remarks>
public abstract class
PayloadCacheRefresherBase<TNotification, TPayload> : JsonCacheRefresherBase<TNotification, TPayload>,
IPayloadCacheRefresher<TPayload>
where TNotification : CacheRefresherNotification
{
/// <summary>
/// Initializes a new instance of the <see cref="PayloadCacheRefresherBase{TInstanceType, TPayload}" />.
/// </summary>
/// <param name="appCaches">A cache helper.</param>
/// <param name="serializer"></param>
/// <param name="eventAggregator"></param>
/// <param name="factory"></param>
protected PayloadCacheRefresherBase(AppCaches appCaches, IJsonSerializer serializer, IEventAggregator eventAggregator, ICacheRefresherNotificationFactory factory)
: base(appCaches, serializer, eventAggregator, factory)
{
}
#region Refresher
public override void Refresh(string json)
{
TPayload[]? payload = Deserialize(json);
if (payload is not null)
{
Refresh(payload);
}
}
/// <summary>
/// Refreshes as specified by a payload.
/// </summary>
/// <param name="payloads">The payload.</param>
public virtual void Refresh(TPayload[] payloads) =>
OnCacheUpdated(NotificationFactory.Create<TNotification>(payloads, MessageType.RefreshByPayload));
#endregion
}