using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Serialization;
using Umbraco.Cms.Core.Sync;
namespace Umbraco.Cms.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 TNotification : CacheRefresherNotification
{
protected IJsonSerializer JsonSerializer { get; }
///
/// Initializes a new instance of the .
///
/// A cache helper.
protected JsonCacheRefresherBase(
AppCaches appCaches,
IJsonSerializer jsonSerializer,
IEventAggregator eventAggregator,
ICacheRefresherNotificationFactory factory)
: base(appCaches, eventAggregator, factory)
{
JsonSerializer = jsonSerializer;
}
///
/// Refreshes as specified by a json payload.
///
/// The json payload.
public virtual void Refresh(string json)
{
OnCacheUpdated(NotificationFactory.Create(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
}
}