2014-03-06 17:50:08 +11:00
|
|
|
|
using System;
|
2014-04-23 20:19:36 +10:00
|
|
|
|
using System.Web.Script.Serialization;
|
2014-09-05 12:16:04 +02:00
|
|
|
|
using umbraco;
|
2015-01-13 13:25:36 +11:00
|
|
|
|
using Umbraco.Core;
|
2014-03-06 17:50:08 +11:00
|
|
|
|
using Umbraco.Core.Cache;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
2014-04-23 20:19:36 +10:00
|
|
|
|
using System.Linq;
|
2014-05-13 10:40:56 +10:00
|
|
|
|
using Umbraco.Core.Persistence.Caching;
|
2015-01-13 13:25:36 +11:00
|
|
|
|
using Umbraco.Core.Persistence.Repositories;
|
2014-04-23 20:19:36 +10:00
|
|
|
|
using Umbraco.Core.Sync;
|
2014-03-06 17:50:08 +11:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Cache
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2014-05-13 10:40:56 +10:00
|
|
|
|
/// A cache refresher used for non-published content, this is primarily to notify Examine indexes to update and to refresh the RuntimeCacheRefresher
|
2014-03-06 17:50:08 +11:00
|
|
|
|
/// </summary>
|
2014-04-23 20:19:36 +10:00
|
|
|
|
public sealed class UnpublishedPageCacheRefresher : TypedCacheRefresherBase<UnpublishedPageCacheRefresher, IContent>, IJsonCacheRefresher
|
2014-03-06 17:50:08 +11:00
|
|
|
|
{
|
|
|
|
|
|
protected override UnpublishedPageCacheRefresher Instance
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return this; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Guid UniqueIdentifier
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return new Guid(DistributedCache.UnpublishedPageCacheRefresherId); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string Name
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return "Unpublished Page Refresher"; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-04-23 20:19:36 +10:00
|
|
|
|
#region Static helpers
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Converts the json to a JsonPayload object
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="json"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
internal static JsonPayload[] DeserializeFromJsonPayload(string json)
|
|
|
|
|
|
{
|
|
|
|
|
|
var serializer = new JavaScriptSerializer();
|
|
|
|
|
|
var jsonObject = serializer.Deserialize<JsonPayload[]>(json);
|
|
|
|
|
|
return jsonObject;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
internal static string SerializeToJsonPayloadForPermanentDeletion(params int[] contentIds)
|
|
|
|
|
|
{
|
|
|
|
|
|
var serializer = new JavaScriptSerializer();
|
|
|
|
|
|
var items = contentIds.Select(x => new JsonPayload
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = x,
|
|
|
|
|
|
Operation = OperationType.Deleted
|
|
|
|
|
|
}).ToArray();
|
|
|
|
|
|
var json = serializer.Serialize(items);
|
|
|
|
|
|
return json;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Sub classes
|
|
|
|
|
|
|
|
|
|
|
|
internal enum OperationType
|
|
|
|
|
|
{
|
|
|
|
|
|
Deleted
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
internal class JsonPayload
|
|
|
|
|
|
{
|
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
|
public OperationType Operation { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2014-05-13 10:40:56 +10:00
|
|
|
|
public override void RefreshAll()
|
|
|
|
|
|
{
|
2015-01-13 13:25:36 +11:00
|
|
|
|
//RuntimeCacheProvider.Current.Clear(typeof(IContent));
|
|
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheObjectTypes<IContent>();
|
2014-05-13 10:40:56 +10:00
|
|
|
|
base.RefreshAll();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Refresh(int id)
|
|
|
|
|
|
{
|
2015-01-13 13:25:36 +11:00
|
|
|
|
//RuntimeCacheProvider.Current.Delete(typeof(IContent), id);
|
|
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(RepositoryBase.GetCacheIdKey<IContent>(id));
|
2014-09-05 12:16:04 +02:00
|
|
|
|
content.Instance.UpdateSortOrder(id);
|
2014-05-13 10:40:56 +10:00
|
|
|
|
base.Refresh(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Remove(int id)
|
|
|
|
|
|
{
|
2015-01-13 13:25:36 +11:00
|
|
|
|
//RuntimeCacheProvider.Current.Delete(typeof(IContent), id);
|
|
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(RepositoryBase.GetCacheIdKey<IContent>(id));
|
2014-05-13 10:40:56 +10:00
|
|
|
|
base.Remove(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void Refresh(IContent instance)
|
|
|
|
|
|
{
|
2015-01-13 13:25:36 +11:00
|
|
|
|
//RuntimeCacheProvider.Current.Delete(typeof(IContent), instance.Id);
|
|
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(RepositoryBase.GetCacheIdKey<IContent>(instance.Id));
|
2014-09-05 12:16:04 +02:00
|
|
|
|
content.Instance.UpdateSortOrder(instance);
|
2014-05-13 10:40:56 +10:00
|
|
|
|
base.Refresh(instance);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Remove(IContent instance)
|
|
|
|
|
|
{
|
2015-01-13 13:25:36 +11:00
|
|
|
|
//RuntimeCacheProvider.Current.Delete(typeof(IContent), instance.Id);
|
|
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(RepositoryBase.GetCacheIdKey<IContent>(instance.Id));
|
2014-05-13 10:40:56 +10:00
|
|
|
|
base.Remove(instance);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-04-23 20:19:36 +10:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Implement the IJsonCacheRefresher so that we can bulk delete the cache based on multiple IDs for when the recycle bin is emptied
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="jsonPayload"></param>
|
|
|
|
|
|
public void Refresh(string jsonPayload)
|
|
|
|
|
|
{
|
2014-05-13 10:40:56 +10:00
|
|
|
|
foreach (var payload in DeserializeFromJsonPayload(jsonPayload))
|
|
|
|
|
|
{
|
2015-01-13 13:25:36 +11:00
|
|
|
|
//RuntimeCacheProvider.Current.Delete(typeof(IContent), payload.Id);
|
|
|
|
|
|
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(RepositoryBase.GetCacheIdKey<IContent>(payload.Id));
|
2014-09-05 12:16:04 +02:00
|
|
|
|
content.Instance.UpdateSortOrder(payload.Id);
|
2014-05-13 10:40:56 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-04-23 20:19:36 +10:00
|
|
|
|
OnCacheUpdated(Instance, new CacheRefresherEventArgs(jsonPayload, MessageType.RefreshByJson));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-03-06 17:50:08 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|