U4-8447 - prepare for NuCache (work-in-progress)

This commit is contained in:
Stephan
2016-05-26 17:12:04 +02:00
parent 8682940efb
commit 06574b8b40
197 changed files with 9380 additions and 9956 deletions

View File

@@ -1,72 +1,96 @@
using System;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.PublishedCache.XmlPublishedCache;
namespace Umbraco.Web.Cache
{
/// <summary>
/// A cache refresher to ensure language cache is refreshed when languages change
/// </summary>
public sealed class DomainCacheRefresher : CacheRefresherBase<DomainCacheRefresher>
public sealed class DomainCacheRefresher : PayloadCacheRefresherBase<DomainCacheRefresher, DomainCacheRefresher.JsonPayload>
{
public DomainCacheRefresher(CacheHelper cacheHelper) : base(cacheHelper)
private readonly IFacadeService _facadeService;
public DomainCacheRefresher(CacheHelper cacheHelper, IFacadeService facadeService)
: base(cacheHelper)
{
_facadeService = facadeService;
}
protected override DomainCacheRefresher Instance
#region Define
protected override DomainCacheRefresher Instance => this;
public static readonly Guid UniqueId = Guid.Parse("11290A79-4B57-4C99-AD72-7748A3CF38AF");
public override Guid RefresherUniqueId => UniqueId;
public override string Name => "Domain Cache Refresher";
#endregion
#region Refresher
public override void Refresh(JsonPayload[] payloads)
{
get { return this; }
ClearAllIsolatedCacheByEntityType<IDomain>();
// note: must do what's above FIRST else the repositories still have the old cached
// content and when the PublishedCachesService is notified of changes it does not see
// the new content...
// notify
_facadeService.Notify(payloads);
// then trigger event
base.Refresh(payloads);
}
public override Guid UniqueIdentifier
{
get { return new Guid(DistributedCache.DomainCacheRefresherId); }
}
public override string Name
{
get { return "Domain cache refresher"; }
}
// these events should never trigger
// everything should be PAYLOAD/JSON
public override void RefreshAll()
{
ClearCache();
base.RefreshAll();
throw new NotSupportedException();
}
public override void Refresh(int id)
{
ClearCache();
base.Refresh(id);
throw new NotSupportedException();
}
public override void Refresh(Guid id)
{
throw new NotSupportedException();
}
public override void Remove(int id)
{
ClearCache();
base.Remove(id);
throw new NotSupportedException();
}
private void ClearCache()
{
ClearAllIsolatedCacheByEntityType<IDomain>();
#endregion
//TODO: Fix this - if we keep this logic here to clear this cache, then we'll need to use IUmbracoContextAccessor since
// instances of the cache refreshers are singletons, not transient
//
// SD: we need to clear the routes cache here!
// zpqrtbnk: no, not here, in fact the caches should subsribe to refresh events else we
// are creating a nasty dependency - but keep it like that for the time being while
// SD is cleaning cache refreshers up.
if (UmbracoContext.Current != null)
#region Json
public class JsonPayload
{
public JsonPayload(int id, ChangeTypes changeType)
{
var contentCache = UmbracoContext.Current.ContentCache.InnerCache as PublishedContentCache;
if (contentCache != null)
contentCache.RoutesCache.Clear();
Id = id;
ChangeType = changeType;
}
public int Id { get; }
public ChangeTypes ChangeType { get; }
}
public enum ChangeTypes : byte // fixme should NOT be here !?
{
None = 0,
RefreshAll = 1,
Refresh = 2,
Remove = 3
}
#endregion
}
}