2021-03-15 13:39:34 +11:00
|
|
|
using Umbraco.Cms.Core.Events;
|
2021-03-12 21:48:24 +01:00
|
|
|
using Umbraco.Cms.Core.Serialization;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Core.Sync;
|
2018-06-29 19:52:40 +02:00
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Core.Cache
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A base class for "json" cache refreshers.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="TInstanceType">The actual cache refresher type.</typeparam>
|
|
|
|
|
/// <remarks>The actual cache refresher type is used for strongly typed events.</remarks>
|
2021-03-12 21:48:24 +01:00
|
|
|
public abstract class JsonCacheRefresherBase<TNotification, TJsonPayload> : CacheRefresherBase<TNotification>, IJsonCacheRefresher
|
2021-03-15 13:39:34 +11:00
|
|
|
where TNotification : CacheRefresherNotification
|
2018-06-29 19:52:40 +02:00
|
|
|
{
|
2020-01-22 14:09:20 +01:00
|
|
|
protected IJsonSerializer JsonSerializer { get; }
|
|
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="JsonCacheRefresherBase{TInstanceType}"/>.
|
|
|
|
|
/// </summary>
|
2019-01-17 08:34:29 +01:00
|
|
|
/// <param name="appCaches">A cache helper.</param>
|
2021-03-12 21:48:24 +01:00
|
|
|
protected JsonCacheRefresherBase(
|
|
|
|
|
AppCaches appCaches,
|
|
|
|
|
IJsonSerializer jsonSerializer,
|
2021-03-15 13:39:34 +11:00
|
|
|
IEventAggregator eventAggregator,
|
|
|
|
|
ICacheRefresherNotificationFactory factory)
|
|
|
|
|
: base(appCaches, eventAggregator, factory)
|
2020-01-22 14:09:20 +01:00
|
|
|
{
|
|
|
|
|
JsonSerializer = jsonSerializer;
|
|
|
|
|
}
|
2018-06-29 19:52:40 +02:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Refreshes as specified by a json payload.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="json">The json payload.</param>
|
|
|
|
|
public virtual void Refresh(string json)
|
|
|
|
|
{
|
2021-03-15 13:39:34 +11:00
|
|
|
OnCacheUpdated(NotificationFactory.Create<TNotification>(json, MessageType.RefreshByJson));
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
2020-01-22 14:09:20 +01:00
|
|
|
|
|
|
|
|
#region Json
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Deserializes a json payload into an object payload.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="json">The json payload.</param>
|
|
|
|
|
/// <returns>The deserialized object payload.</returns>
|
|
|
|
|
public TJsonPayload[] Deserialize(string json)
|
|
|
|
|
{
|
|
|
|
|
return JsonSerializer.Deserialize<TJsonPayload[]>(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string Serialize(params TJsonPayload[] jsonPayloads)
|
|
|
|
|
{
|
|
|
|
|
return JsonSerializer.Serialize(jsonPayloads);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2018-06-29 19:52:40 +02:00
|
|
|
}
|
|
|
|
|
}
|