using Umbraco.Core.Serialization; using Umbraco.Core.Sync; namespace Umbraco.Core.Cache { /// /// A base class for "json" cache refreshers. /// /// The actual cache refresher type. /// The actual cache refresher type is used for strongly typed events. public abstract class JsonCacheRefresherBase : CacheRefresherBase, IJsonCacheRefresher where TInstanceType : class, ICacheRefresher { protected IJsonSerializer JsonSerializer { get; } /// /// Initializes a new instance of the . /// /// A cache helper. protected JsonCacheRefresherBase(AppCaches appCaches, IJsonSerializer jsonSerializer) : base(appCaches) { JsonSerializer = jsonSerializer; } /// /// Refreshes as specified by a json payload. /// /// The json payload. public virtual void Refresh(string json) { OnCacheUpdated(This, new CacheRefresherEventArgs(json, MessageType.RefreshByJson)); } #region Json /// /// Deserializes a json payload into an object payload. /// /// The json payload. /// The deserialized object payload. public TJsonPayload[] Deserialize(string json) { return JsonSerializer.Deserialize(json); } public string Serialize(params TJsonPayload[] jsonPayloads) { return JsonSerializer.Serialize(jsonPayloads); } #endregion } }