using Newtonsoft.Json; using Umbraco.Core.Sync; namespace Umbraco.Core.Cache { /// /// A base class for "payload" class refreshers. /// /// The actual cache refresher type. /// The payload type. /// The actual cache refresher type is used for strongly typed events. public abstract class PayloadCacheRefresherBase : JsonCacheRefresherBase, IPayloadCacheRefresher where TInstanceType : class, ICacheRefresher { /// /// Initializes a new instance of the . /// /// A cache helper. protected PayloadCacheRefresherBase(AppCaches appCaches) : base(appCaches) { } #region Json /// /// Deserializes a json payload into an object payload. /// /// The json payload. /// The deserialized object payload. protected virtual TPayload[] Deserialize(string json) { return JsonConvert.DeserializeObject(json); } #endregion #region Refresher public override void Refresh(string json) { var payload = Deserialize(json); Refresh(payload); } /// /// Refreshes as specified by a payload. /// /// The payload. public virtual void Refresh(TPayload[] payloads) { OnCacheUpdated(This, new CacheRefresherEventArgs(payloads, MessageType.RefreshByPayload)); } #endregion } }