2016-05-26 17:12:04 +02:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using Umbraco.Core.Sync;
|
2015-04-08 14:21:58 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Cache
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2016-05-26 17:12:04 +02:00
|
|
|
|
/// A base class for "payload" class refreshers.
|
2015-04-08 14:21:58 +02:00
|
|
|
|
/// </summary>
|
2016-05-26 17:12:04 +02:00
|
|
|
|
/// <typeparam name="TInstanceType">The actual cache refresher type.</typeparam>
|
|
|
|
|
|
/// <typeparam name="TPayload">The payload type.</typeparam>
|
|
|
|
|
|
/// <remarks>The actual cache refresher type is used for strongly typed events.</remarks>
|
|
|
|
|
|
public abstract class PayloadCacheRefresherBase<TInstanceType, TPayload> : JsonCacheRefresherBase<TInstanceType>, IPayloadCacheRefresher<TPayload>
|
|
|
|
|
|
where TInstanceType : class, ICacheRefresher
|
2015-04-08 14:21:58 +02:00
|
|
|
|
{
|
2016-05-26 17:12:04 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Initializes a new instance of the <see cref="PayloadCacheRefresherBase{TInstanceType, TPayload}"/>.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="cacheHelper">A cache helper.</param>
|
2016-05-18 18:44:08 +02:00
|
|
|
|
protected PayloadCacheRefresherBase(CacheHelper cacheHelper) : base(cacheHelper)
|
2016-05-26 17:12:04 +02: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>
|
|
|
|
|
|
protected virtual TPayload[] Deserialize(string json)
|
2016-05-18 18:44:08 +02:00
|
|
|
|
{
|
2016-05-26 17:12:04 +02:00
|
|
|
|
return JsonConvert.DeserializeObject<TPayload[]>(json);
|
2016-05-18 18:44:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-26 17:12:04 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Refresher
|
2015-04-08 14:21:58 +02:00
|
|
|
|
|
|
|
|
|
|
public override void Refresh(string json)
|
|
|
|
|
|
{
|
|
|
|
|
|
var payload = Deserialize(json);
|
|
|
|
|
|
Refresh(payload);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-05-26 17:12:04 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Refreshes as specified by a payload.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="payloads">The payload.</param>
|
|
|
|
|
|
public virtual void Refresh(TPayload[] payloads)
|
2015-04-08 14:21:58 +02:00
|
|
|
|
{
|
2017-07-11 19:21:13 +02:00
|
|
|
|
OnCacheUpdated(This, new CacheRefresherEventArgs(payloads, MessageType.RefreshByPayload));
|
2015-04-08 14:21:58 +02:00
|
|
|
|
}
|
2016-05-26 17:12:04 +02:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2015-04-08 14:21:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|