So long Facade
This commit is contained in:
@@ -1,21 +1,19 @@
|
||||
using System;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements a facade.
|
||||
/// Implements a published snapshot.
|
||||
/// </summary>
|
||||
class Facade : IFacade
|
||||
class PublishedShapshot : IPublishedShapshot
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Facade"/> class with a content cache
|
||||
/// Initializes a new instance of the <see cref="PublishedShapshot"/> class with a content cache
|
||||
/// and a media cache.
|
||||
/// </summary>
|
||||
public Facade(
|
||||
public PublishedShapshot(
|
||||
PublishedContentCache contentCache,
|
||||
PublishedMediaCache mediaCache,
|
||||
PublishedMemberCache memberCache,
|
||||
@@ -40,10 +38,10 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
public IDomainCache DomainCache { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ICacheProvider FacadeCache => null;
|
||||
public ICacheProvider SnapshotCache => null;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ICacheProvider SnapshotCache => null;
|
||||
public ICacheProvider ElementsCache => null;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IDisposable ForcedPreview(bool preview, Action<bool> callback = null)
|
||||
@@ -16,9 +16,9 @@ using Umbraco.Web.Cache;
|
||||
namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements a facade service.
|
||||
/// Implements a published snapshot service.
|
||||
/// </summary>
|
||||
internal class FacadeService : FacadeServiceBase
|
||||
internal class PublishedSnapshotService : PublishedSnapshotServiceBase
|
||||
{
|
||||
private readonly XmlStore _xmlStore;
|
||||
private readonly RoutesCache _routesCache;
|
||||
@@ -32,51 +32,51 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
#region Constructors
|
||||
|
||||
// used in WebBootManager + tests
|
||||
public FacadeService(ServiceContext serviceContext,
|
||||
public PublishedSnapshotService(ServiceContext serviceContext,
|
||||
IPublishedContentTypeFactory publishedContentTypeFactory,
|
||||
IScopeProvider scopeProvider,
|
||||
IScopeUnitOfWorkProvider uowProvider,
|
||||
ICacheProvider requestCache,
|
||||
IEnumerable<IUrlSegmentProvider> segmentProviders,
|
||||
IFacadeAccessor facadeAccessor,
|
||||
IPublishedSnapshotAccessor publishedSnapshotAccessor,
|
||||
ILogger logger,
|
||||
MainDom mainDom,
|
||||
bool testing = false, bool enableRepositoryEvents = true)
|
||||
: this(serviceContext, publishedContentTypeFactory, scopeProvider, uowProvider, requestCache, segmentProviders, facadeAccessor, logger, null, mainDom, testing, enableRepositoryEvents)
|
||||
: this(serviceContext, publishedContentTypeFactory, scopeProvider, uowProvider, requestCache, segmentProviders, publishedSnapshotAccessor, logger, null, mainDom, testing, enableRepositoryEvents)
|
||||
{ }
|
||||
|
||||
// used in some tests
|
||||
internal FacadeService(ServiceContext serviceContext,
|
||||
internal PublishedSnapshotService(ServiceContext serviceContext,
|
||||
IPublishedContentTypeFactory publishedContentTypeFactory,
|
||||
IScopeProvider scopeProvider,
|
||||
IScopeUnitOfWorkProvider uowProvider,
|
||||
ICacheProvider requestCache,
|
||||
IFacadeAccessor facadeAccessor,
|
||||
IPublishedSnapshotAccessor publishedSnapshotAccessor,
|
||||
ILogger logger,
|
||||
PublishedContentTypeCache contentTypeCache,
|
||||
MainDom mainDom,
|
||||
bool testing, bool enableRepositoryEvents)
|
||||
: this(serviceContext, publishedContentTypeFactory, scopeProvider, uowProvider, requestCache, Enumerable.Empty<IUrlSegmentProvider>(), facadeAccessor, logger, contentTypeCache, mainDom, testing, enableRepositoryEvents)
|
||||
: this(serviceContext, publishedContentTypeFactory, scopeProvider, uowProvider, requestCache, Enumerable.Empty<IUrlSegmentProvider>(), publishedSnapshotAccessor, logger, contentTypeCache, mainDom, testing, enableRepositoryEvents)
|
||||
{ }
|
||||
|
||||
private FacadeService(ServiceContext serviceContext,
|
||||
private PublishedSnapshotService(ServiceContext serviceContext,
|
||||
IPublishedContentTypeFactory publishedContentTypeFactory,
|
||||
IScopeProvider scopeProvider,
|
||||
IScopeUnitOfWorkProvider uowProvider,
|
||||
ICacheProvider requestCache,
|
||||
IEnumerable<IUrlSegmentProvider> segmentProviders,
|
||||
IFacadeAccessor facadeAccessor,
|
||||
IPublishedSnapshotAccessor publishedSnapshotAccessor,
|
||||
ILogger logger,
|
||||
PublishedContentTypeCache contentTypeCache,
|
||||
MainDom mainDom,
|
||||
bool testing, bool enableRepositoryEvents)
|
||||
: base(facadeAccessor)
|
||||
: base(publishedSnapshotAccessor)
|
||||
{
|
||||
_routesCache = new RoutesCache();
|
||||
_contentTypeCache = contentTypeCache
|
||||
?? new PublishedContentTypeCache(serviceContext.ContentTypeService, serviceContext.MediaTypeService, serviceContext.MemberTypeService, publishedContentTypeFactory, logger);
|
||||
|
||||
_xmlStore = new XmlStore(serviceContext, scopeProvider, uowProvider, _routesCache, _contentTypeCache, segmentProviders, facadeAccessor, mainDom, testing, enableRepositoryEvents);
|
||||
_xmlStore = new XmlStore(serviceContext, scopeProvider, uowProvider, _routesCache, _contentTypeCache, segmentProviders, publishedSnapshotAccessor, mainDom, testing, enableRepositoryEvents);
|
||||
|
||||
_domainService = serviceContext.DomainService;
|
||||
_memberService = serviceContext.MemberService;
|
||||
@@ -117,7 +117,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
|
||||
#region Caches
|
||||
|
||||
public override IFacade CreateFacade(string previewToken)
|
||||
public override IPublishedShapshot CreatePublishedSnapshot(string previewToken)
|
||||
{
|
||||
// use _requestCache to store recursive properties lookup, etc. both in content
|
||||
// and media cache. Life span should be the current request. Or, ideally
|
||||
@@ -126,7 +126,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
|
||||
var domainCache = new DomainCache(_domainService);
|
||||
|
||||
return new Facade(
|
||||
return new PublishedShapshot(
|
||||
new PublishedContentCache(_xmlStore, domainCache, _requestCache, _contentTypeCache, _routesCache, previewToken),
|
||||
new PublishedMediaCache(_xmlStore, _mediaService, _userService, _requestCache, _contentTypeCache),
|
||||
new PublishedMemberCache(_xmlStore, _requestCache, _memberService, _contentTypeCache),
|
||||
@@ -20,14 +20,14 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
base.Compose(composition);
|
||||
|
||||
// register the XML facade service
|
||||
composition.SetFacadeService(factory => new FacadeService(
|
||||
composition.SetPublishedSnapshotService(factory => new PublishedSnapshotService(
|
||||
factory.GetInstance<ServiceContext>(),
|
||||
factory.GetInstance<IPublishedContentTypeFactory>(),
|
||||
factory.GetInstance<IScopeProvider>(),
|
||||
factory.GetInstance<IScopeUnitOfWorkProvider>(),
|
||||
factory.GetInstance<CacheHelper>().RequestCache,
|
||||
factory.GetInstance<UrlSegmentProviderCollection>(),
|
||||
factory.GetInstance<IFacadeAccessor>(),
|
||||
factory.GetInstance<IPublishedSnapshotAccessor>(),
|
||||
factory.GetInstance<ILogger>(),
|
||||
factory.GetInstance<MainDom>()));
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
composition.HealthChecks().Add<XmlDataIntegrityHealthCheck>();
|
||||
}
|
||||
|
||||
public void Initialize(IFacadeService service)
|
||||
public void Initialize(IPublishedSnapshotService service)
|
||||
{
|
||||
// nothing - this just ensures that the service is created at boot time
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
|
||||
private readonly XmlNode _xmlNode;
|
||||
private readonly bool _isPreviewing;
|
||||
private readonly ICacheProvider _cacheProvider; // at facade/request level (see PublishedContentCache)
|
||||
private readonly ICacheProvider _cacheProvider; // at snapshot/request level (see PublishedContentCache)
|
||||
private readonly PublishedContentTypeCache _contentTypeCache;
|
||||
|
||||
private bool _nodeInitialized;
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
if (_objectValueComputed) return _objectValue;
|
||||
var inter = PropertyType.ConvertSourceToInter(_content, _sourceValue, _isPreviewing);
|
||||
// initial reference cache level always is .Content
|
||||
_objectValue = PropertyType.ConvertInterToObject(_content, PropertyCacheLevel.Content, inter, _isPreviewing);
|
||||
_objectValue = PropertyType.ConvertInterToObject(_content, PropertyCacheLevel.Element, inter, _isPreviewing);
|
||||
_objectValueComputed = true;
|
||||
return _objectValue;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
/// Represents the Xml storage for the Xml published cache.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>One instance of <see cref="XmlStore"/> is instanciated by the <see cref="FacadeService"/> and
|
||||
/// <para>One instance of <see cref="XmlStore"/> is instanciated by the <see cref="PublishedSnapshotService"/> and
|
||||
/// then passed to all <see cref="PublishedContentCache"/> instances that are created (one per request).</para>
|
||||
/// <para>This class should *not* be public.</para>
|
||||
/// </remarks>
|
||||
@@ -47,7 +47,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
private volatile bool _released;
|
||||
private bool _withRepositoryEvents;
|
||||
|
||||
private readonly IFacadeAccessor _facadeAccessor;
|
||||
private readonly IPublishedSnapshotAccessor _publishedSnapshotAccessor;
|
||||
private readonly PublishedContentTypeCache _contentTypeCache;
|
||||
private readonly RoutesCache _routesCache;
|
||||
private readonly ServiceContext _serviceContext; // fixme WHY
|
||||
@@ -61,15 +61,15 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
/// </summary>
|
||||
/// <remarks>The default constructor will boot the cache, load data from file or database, /// wire events in order to manage changes, etc.</remarks>
|
||||
public XmlStore(ServiceContext serviceContext, IScopeProvider scopeProvider, IScopeUnitOfWorkProvider uowProvider, RoutesCache routesCache, PublishedContentTypeCache contentTypeCache,
|
||||
IEnumerable<IUrlSegmentProvider> segmentProviders, IFacadeAccessor facadeAccessor, MainDom mainDom)
|
||||
: this(serviceContext, scopeProvider, uowProvider, routesCache, contentTypeCache, segmentProviders, facadeAccessor, mainDom, false, false)
|
||||
IEnumerable<IUrlSegmentProvider> segmentProviders, IPublishedSnapshotAccessor publishedSnapshotAccessor, MainDom mainDom)
|
||||
: this(serviceContext, scopeProvider, uowProvider, routesCache, contentTypeCache, segmentProviders, publishedSnapshotAccessor, mainDom, false, false)
|
||||
{ }
|
||||
|
||||
// internal for unit tests
|
||||
// no file nor db, no config check
|
||||
// fixme - er, we DO have a DB?
|
||||
internal XmlStore(ServiceContext serviceContext, IScopeProvider scopeProvider, IScopeUnitOfWorkProvider uowProvider, RoutesCache routesCache, PublishedContentTypeCache contentTypeCache,
|
||||
IEnumerable<IUrlSegmentProvider> segmentProviders, IFacadeAccessor facadeAccessor, MainDom mainDom,
|
||||
IEnumerable<IUrlSegmentProvider> segmentProviders, IPublishedSnapshotAccessor publishedSnapshotAccessor, MainDom mainDom,
|
||||
bool testing, bool enableRepositoryEvents)
|
||||
{
|
||||
if (testing == false)
|
||||
@@ -80,7 +80,7 @@ namespace Umbraco.Web.PublishedCache.XmlPublishedCache
|
||||
_uowProvider = uowProvider;
|
||||
_routesCache = routesCache;
|
||||
_contentTypeCache = contentTypeCache;
|
||||
_facadeAccessor = facadeAccessor;
|
||||
_publishedSnapshotAccessor = publishedSnapshotAccessor;
|
||||
|
||||
InitializeSerializers(segmentProviders);
|
||||
|
||||
@@ -593,17 +593,17 @@ AND (umbracoNode.id=@id)";
|
||||
// should we have async versions that would do: ?
|
||||
// var releaser = await _xmlLock.LockAsync();
|
||||
//
|
||||
// fixme - not sure about the "resync current facade" thing here, see 7.6...
|
||||
// fixme - not sure about the "resync current published snapshot" thing here, see 7.6...
|
||||
|
||||
// gets a locked safe read access to the main xml
|
||||
private SafeXmlReaderWriter GetSafeXmlReader()
|
||||
{
|
||||
return SafeXmlReaderWriter.Get(_scopeProvider, _xmlLock, _xml,
|
||||
ResyncCurrentFacade,
|
||||
ResyncCurrentPublishedSnapshot,
|
||||
(xml, registerXmlChange) =>
|
||||
{
|
||||
SetXmlLocked(xml, registerXmlChange);
|
||||
ResyncCurrentFacade(xml);
|
||||
ResyncCurrentPublishedSnapshot(xml);
|
||||
}, false);
|
||||
}
|
||||
|
||||
@@ -611,11 +611,11 @@ AND (umbracoNode.id=@id)";
|
||||
private SafeXmlReaderWriter GetSafeXmlWriter()
|
||||
{
|
||||
return SafeXmlReaderWriter.Get(_scopeProvider, _xmlLock, _xml,
|
||||
ResyncCurrentFacade,
|
||||
ResyncCurrentPublishedSnapshot,
|
||||
(xml, registerXmlChange) =>
|
||||
{
|
||||
SetXmlLocked(xml, registerXmlChange);
|
||||
ResyncCurrentFacade(xml);
|
||||
ResyncCurrentPublishedSnapshot(xml);
|
||||
}, true);
|
||||
}
|
||||
|
||||
@@ -1241,12 +1241,12 @@ ORDER BY umbracoNode.level, umbracoNode.sortOrder";
|
||||
// ignore media and member types - we're not caching them
|
||||
}
|
||||
|
||||
private void ResyncCurrentFacade(XmlDocument xml)
|
||||
private void ResyncCurrentPublishedSnapshot(XmlDocument xml)
|
||||
{
|
||||
var facade = (Facade) _facadeAccessor.Facade;
|
||||
if (facade == null) return;
|
||||
((PublishedContentCache) facade.ContentCache).Resync(xml);
|
||||
((PublishedMediaCache) facade.MediaCache).Resync();
|
||||
var publishedSnapshot = (PublishedShapshot) _publishedSnapshotAccessor.PublishedSnapshot;
|
||||
if (publishedSnapshot == null) return;
|
||||
((PublishedContentCache) publishedSnapshot.ContentCache).Resync(xml);
|
||||
((PublishedMediaCache) publishedSnapshot.MediaCache).Resync();
|
||||
|
||||
// not trying to resync members or domains, which are not cached really
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user