Files
Umbraco-CMS/src/Umbraco.PublishedCache.NuCache/PublishedSnapshot.cs

127 lines
3.4 KiB
C#
Raw Normal View History

using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.PublishedCache;
2016-05-27 14:26:28 +02:00
namespace Umbraco.Cms.Infrastructure.PublishedCache;
// implements published snapshot
public class PublishedSnapshot : IPublishedSnapshot
2016-05-27 14:26:28 +02:00
{
private readonly PublishedSnapshotService? _service;
private bool _defaultPreview;
private PublishedSnapshotElements? _elements;
2016-05-27 14:26:28 +02:00
#region Constructors
2016-05-27 14:26:28 +02:00
public PublishedSnapshot(IPublishedSnapshotService service, bool defaultPreview)
{
_service = service as PublishedSnapshotService;
_defaultPreview = defaultPreview;
}
2016-05-27 14:26:28 +02:00
public class PublishedSnapshotElements : IDisposable
{
public void Dispose()
2016-05-27 14:26:28 +02:00
{
ContentCache?.Dispose();
MediaCache?.Dispose();
MemberCache?.Dispose();
}
#pragma warning disable IDE1006 // Naming Styles
public ContentCache? ContentCache;
public MediaCache? MediaCache;
public MemberCache? MemberCache;
public DomainCache? DomainCache;
public IAppCache? SnapshotCache;
public IAppCache? ElementsCache;
#pragma warning restore IDE1006 // Naming Styles
}
2016-05-27 14:26:28 +02:00
private PublishedSnapshotElements Elements
{
get
Examine 2.0 integration (#10241) * Init commit for examine 2.0 work, most old umb examine tests working, probably a lot that doesn't * Gets Umbraco Examine tests passing and makes some sense out of them, fixes some underlying issues. * Large refactor, remove TaskHelper, rename Notifications to be consistent, Gets all examine/lucene indexes building and startup ordered in the correct way, removes old files, creates new IUmbracoIndexingHandler for abstracting out all index operations for umbraco data, abstracts out IIndexRebuilder, Fixes Stack overflow with LiveModelsProvider and loading assemblies, ports some changes from v8 for startup handling with cold boots, refactors out LastSyncedFileManager * fix up issues with rebuilding and management dashboard. * removes old files, removes NetworkHelper, fixes LastSyncedFileManager implementation to ensure the machine name is used, fix up logging with cold boot state. * Makes MainDom safer to use and makes PublishedSnapshotService lazily register with MainDom * lazily acquire application id (fix unit tests) * Fixes resource casing and missing test file * Ensures caches when requiring internal services for PublishedSnapshotService, UseNuCache is a separate call, shouldn't be buried in AddWebComponents, was also causing issues in integration tests since nucache was being used for the Id2Key service. * For UmbracoTestServerTestBase enable nucache services * Fixing tests * Fix another test * Fixes tests, use TestHostingEnvironment, make Tests.Common use net5, remove old Lucene.Net.Contrib ref. * Fixes up some review notes * Fixes issue with doubly registering PublishedSnapshotService meanig there could be 2x instances of it * Checks for parseexception when executing the query * Use application root instead of duplicating functionality. * Added Examine project to netcore only solution file * Fixed casing issue with LazyLoad, that is not lowercase. * uses cancellationToken instead of bool flag, fixes always reading lastId from the LastSyncedFileManager, fixes RecurringHostedServiceBase so that there isn't an overlapping thread for the same task type * Fix tests * remove legacy test project from solution file * Fix test Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-05-18 18:31:38 +10:00
{
if (_service == null)
Examine 2.0 integration (#10241) * Init commit for examine 2.0 work, most old umb examine tests working, probably a lot that doesn't * Gets Umbraco Examine tests passing and makes some sense out of them, fixes some underlying issues. * Large refactor, remove TaskHelper, rename Notifications to be consistent, Gets all examine/lucene indexes building and startup ordered in the correct way, removes old files, creates new IUmbracoIndexingHandler for abstracting out all index operations for umbraco data, abstracts out IIndexRebuilder, Fixes Stack overflow with LiveModelsProvider and loading assemblies, ports some changes from v8 for startup handling with cold boots, refactors out LastSyncedFileManager * fix up issues with rebuilding and management dashboard. * removes old files, removes NetworkHelper, fixes LastSyncedFileManager implementation to ensure the machine name is used, fix up logging with cold boot state. * Makes MainDom safer to use and makes PublishedSnapshotService lazily register with MainDom * lazily acquire application id (fix unit tests) * Fixes resource casing and missing test file * Ensures caches when requiring internal services for PublishedSnapshotService, UseNuCache is a separate call, shouldn't be buried in AddWebComponents, was also causing issues in integration tests since nucache was being used for the Id2Key service. * For UmbracoTestServerTestBase enable nucache services * Fixing tests * Fix another test * Fixes tests, use TestHostingEnvironment, make Tests.Common use net5, remove old Lucene.Net.Contrib ref. * Fixes up some review notes * Fixes issue with doubly registering PublishedSnapshotService meanig there could be 2x instances of it * Checks for parseexception when executing the query * Use application root instead of duplicating functionality. * Added Examine project to netcore only solution file * Fixed casing issue with LazyLoad, that is not lowercase. * uses cancellationToken instead of bool flag, fixes always reading lastId from the LastSyncedFileManager, fixes RecurringHostedServiceBase so that there isn't an overlapping thread for the same task type * Fix tests * remove legacy test project from solution file * Fix test Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-05-18 18:31:38 +10:00
{
throw new InvalidOperationException(
$"The {typeof(PublishedSnapshot)} cannot be used when the {typeof(IPublishedSnapshotService)} is not the default type {typeof(PublishedSnapshotService)}");
Examine 2.0 integration (#10241) * Init commit for examine 2.0 work, most old umb examine tests working, probably a lot that doesn't * Gets Umbraco Examine tests passing and makes some sense out of them, fixes some underlying issues. * Large refactor, remove TaskHelper, rename Notifications to be consistent, Gets all examine/lucene indexes building and startup ordered in the correct way, removes old files, creates new IUmbracoIndexingHandler for abstracting out all index operations for umbraco data, abstracts out IIndexRebuilder, Fixes Stack overflow with LiveModelsProvider and loading assemblies, ports some changes from v8 for startup handling with cold boots, refactors out LastSyncedFileManager * fix up issues with rebuilding and management dashboard. * removes old files, removes NetworkHelper, fixes LastSyncedFileManager implementation to ensure the machine name is used, fix up logging with cold boot state. * Makes MainDom safer to use and makes PublishedSnapshotService lazily register with MainDom * lazily acquire application id (fix unit tests) * Fixes resource casing and missing test file * Ensures caches when requiring internal services for PublishedSnapshotService, UseNuCache is a separate call, shouldn't be buried in AddWebComponents, was also causing issues in integration tests since nucache was being used for the Id2Key service. * For UmbracoTestServerTestBase enable nucache services * Fixing tests * Fix another test * Fixes tests, use TestHostingEnvironment, make Tests.Common use net5, remove old Lucene.Net.Contrib ref. * Fixes up some review notes * Fixes issue with doubly registering PublishedSnapshotService meanig there could be 2x instances of it * Checks for parseexception when executing the query * Use application root instead of duplicating functionality. * Added Examine project to netcore only solution file * Fixed casing issue with LazyLoad, that is not lowercase. * uses cancellationToken instead of bool flag, fixes always reading lastId from the LastSyncedFileManager, fixes RecurringHostedServiceBase so that there isn't an overlapping thread for the same task type * Fix tests * remove legacy test project from solution file * Fix test Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-05-18 18:31:38 +10:00
}
2016-05-27 14:26:28 +02:00
return _elements ??= _service.GetElements(_defaultPreview);
2016-05-27 14:26:28 +02:00
}
}
2016-05-27 14:26:28 +02:00
public void Resync()
{
// no lock - published snapshots are single-thread
_elements?.Dispose();
_elements = null;
}
2016-05-27 14:26:28 +02:00
#endregion
2016-05-27 14:26:28 +02:00
#region Caches
2016-05-27 14:26:28 +02:00
public IAppCache? SnapshotCache => Elements.SnapshotCache;
2016-05-27 14:26:28 +02:00
public IAppCache? ElementsCache => Elements.ElementsCache;
2016-05-27 14:26:28 +02:00
#endregion
2016-05-27 14:26:28 +02:00
#region IPublishedSnapshot
2016-05-27 14:26:28 +02:00
public IPublishedContentCache? Content => Elements.ContentCache;
2016-05-27 14:26:28 +02:00
public IPublishedMediaCache? Media => Elements.MediaCache;
2016-05-27 14:26:28 +02:00
public IPublishedMemberCache? Members => Elements.MemberCache;
2016-05-27 14:26:28 +02:00
public IDomainCache? Domains => Elements.DomainCache;
2016-06-09 18:45:16 +02:00
public IDisposable ForcedPreview(bool preview, Action<bool>? callback = null) =>
new ForcedPreviewObject(this, preview, callback);
2016-06-09 18:45:16 +02:00
private class ForcedPreviewObject : DisposableObjectSlim
{
private readonly Action<bool>? _callback;
private readonly bool _origPreview;
private readonly PublishedSnapshot _publishedSnapshot;
2016-06-09 18:45:16 +02:00
public ForcedPreviewObject(PublishedSnapshot publishedShapshot, bool preview, Action<bool>? callback)
{
_publishedSnapshot = publishedShapshot;
_callback = callback;
2016-06-09 18:45:16 +02:00
// save and force
_origPreview = publishedShapshot._defaultPreview;
publishedShapshot._defaultPreview = preview;
2016-06-09 18:45:16 +02:00
}
protected override void DisposeResources()
{
// restore
_publishedSnapshot._defaultPreview = _origPreview;
_callback?.Invoke(_origPreview);
}
}
2016-05-27 14:26:28 +02:00
#endregion
2016-05-27 14:26:28 +02:00
#region IDisposable
2016-05-27 14:26:28 +02:00
private bool _disposed;
public void Dispose()
{
if (_disposed)
2016-05-27 14:26:28 +02:00
{
return;
2016-05-27 14:26:28 +02:00
}
_disposed = true;
_elements?.Dispose();
2016-05-27 14:26:28 +02:00
}
#endregion
2016-05-27 14:26:28 +02:00
}