diff --git a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs index 9a3534cfc4..34ac79a219 100644 --- a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs +++ b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs @@ -47,7 +47,7 @@ namespace Umbraco.Tests.Routing null, // FIXME: PublishedRouter complexities... Mock.Of(), Mock.Of(), - new Umbraco.Web.Cache.BackgroundPublishedSnapshotServiceNotifier( + new Umbraco.Web.Cache.BackgroundPublishedSnapshotNotifier( Factory.GetInstance(), Factory.GetInstance(), Logger) diff --git a/src/Umbraco.Web/Cache/BackgroundPublishedSnapshotServiceNotifier.cs b/src/Umbraco.Web/Cache/BackgroundPublishedSnapshotNotifier.cs similarity index 85% rename from src/Umbraco.Web/Cache/BackgroundPublishedSnapshotServiceNotifier.cs rename to src/Umbraco.Web/Cache/BackgroundPublishedSnapshotNotifier.cs index 725b1389ce..f1da2b6375 100644 --- a/src/Umbraco.Web/Cache/BackgroundPublishedSnapshotServiceNotifier.cs +++ b/src/Umbraco.Web/Cache/BackgroundPublishedSnapshotNotifier.cs @@ -13,9 +13,11 @@ namespace Umbraco.Web.Cache /// /// /// When in Pure Live mode, the models need to be rebuilt before the IPublishedSnapshotService is notified which can result in performance penalties so - /// this performs these actions on a background thread so the user isn't waiting for the rebuilding to occur on a UI thread. + /// this performs these actions on a background thread so the user isn't waiting for the rebuilding to occur on a UI thread. + /// When using this, even when not in Pure Live mode, it still means that the cache is notified on a background thread. + /// In order to wait for the processing to complete, this class has a Wait() method which will block until the processing is finished. /// - public sealed class BackgroundPublishedSnapshotServiceNotifier + public sealed class BackgroundPublishedSnapshotNotifier { private readonly IPublishedModelFactory _publishedModelFactory; private readonly IPublishedSnapshotService _publishedSnapshotService; @@ -27,7 +29,7 @@ namespace Umbraco.Web.Cache /// /// /// - public BackgroundPublishedSnapshotServiceNotifier(IPublishedModelFactory publishedModelFactory, IPublishedSnapshotService publishedSnapshotService, ILogger logger) + public BackgroundPublishedSnapshotNotifier(IPublishedModelFactory publishedModelFactory, IPublishedSnapshotService publishedSnapshotService, ILogger logger) { _publishedModelFactory = publishedModelFactory; _publishedSnapshotService = publishedSnapshotService; @@ -41,7 +43,13 @@ namespace Umbraco.Web.Cache /// /// Blocks until the background operation is completed /// - public void Wait() => _runner.StoppedAwaitable.GetAwaiter().GetResult(); //TODO: do we need a try/catch? + /// Returns true if waiting was necessary + public bool Wait() + { + var running = _runner.IsRunning; + _runner.StoppedAwaitable.GetAwaiter().GetResult(); //TODO: do we need a try/catch? + return running; + } /// /// Notify the of content type changes @@ -101,6 +109,10 @@ namespace Umbraco.Web.Cache _publishedSnapshotService.Notify(_dataTypePayloads); if (_contentTypePayloads != null) _publishedSnapshotService.Notify(_contentTypePayloads); + + //Thread.Sleep(10000); + + var asdf = ""; }); } diff --git a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs index 8ff82b2644..0d38f38362 100644 --- a/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/ContentTypeCacheRefresher.cs @@ -10,11 +10,11 @@ namespace Umbraco.Web.Cache { public sealed class ContentTypeCacheRefresher : PayloadCacheRefresherBase { - private readonly BackgroundPublishedSnapshotServiceNotifier _backgroundModelFactory; + private readonly BackgroundPublishedSnapshotNotifier _backgroundModelFactory; private readonly IContentTypeCommonRepository _contentTypeCommonRepository; private readonly IdkMap _idkMap; - public ContentTypeCacheRefresher(AppCaches appCaches, BackgroundPublishedSnapshotServiceNotifier backgroundModelFactory, IdkMap idkMap, IContentTypeCommonRepository contentTypeCommonRepository) + public ContentTypeCacheRefresher(AppCaches appCaches, BackgroundPublishedSnapshotNotifier backgroundModelFactory, IdkMap idkMap, IContentTypeCommonRepository contentTypeCommonRepository) : base(appCaches) { _backgroundModelFactory = backgroundModelFactory; diff --git a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs b/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs index 5363182a08..97367be495 100644 --- a/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs +++ b/src/Umbraco.Web/Cache/DataTypeCacheRefresher.cs @@ -9,10 +9,10 @@ namespace Umbraco.Web.Cache public sealed class DataTypeCacheRefresher : PayloadCacheRefresherBase { - private readonly BackgroundPublishedSnapshotServiceNotifier _backgroundModelFactory; + private readonly BackgroundPublishedSnapshotNotifier _backgroundModelFactory; private readonly IdkMap _idkMap; - public DataTypeCacheRefresher(AppCaches appCaches, BackgroundPublishedSnapshotServiceNotifier backgroundModelFactory, IdkMap idkMap) + public DataTypeCacheRefresher(AppCaches appCaches, BackgroundPublishedSnapshotNotifier backgroundModelFactory, IdkMap idkMap) : base(appCaches) { _backgroundModelFactory = backgroundModelFactory; diff --git a/src/Umbraco.Web/Runtime/WebInitialComposer.cs b/src/Umbraco.Web/Runtime/WebInitialComposer.cs index d59caff63c..4b4fb488e5 100644 --- a/src/Umbraco.Web/Runtime/WebInitialComposer.cs +++ b/src/Umbraco.Web/Runtime/WebInitialComposer.cs @@ -125,7 +125,7 @@ namespace Umbraco.Web.Runtime // register distributed cache composition.RegisterUnique(f => new DistributedCache()); - composition.RegisterUnique(); + composition.RegisterUnique(); // replace some services composition.RegisterUnique(); diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index b5641e8aae..1a23ae7f65 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -115,7 +115,7 @@ - + diff --git a/src/Umbraco.Web/UmbracoInjectedModule.cs b/src/Umbraco.Web/UmbracoInjectedModule.cs index b16d86a8ba..99d167fbd3 100644 --- a/src/Umbraco.Web/UmbracoInjectedModule.cs +++ b/src/Umbraco.Web/UmbracoInjectedModule.cs @@ -19,6 +19,7 @@ using Umbraco.Core.Services; using Umbraco.Web.Composing; using Umbraco.Web.PublishedCache; using Umbraco.Web.Cache; +using Umbraco.Web.PublishedCache.NuCache; namespace Umbraco.Web { @@ -49,7 +50,7 @@ namespace Umbraco.Web private readonly IPublishedRouter _publishedRouter; private readonly IVariationContextAccessor _variationContextAccessor; private readonly IUmbracoContextFactory _umbracoContextFactory; - private readonly BackgroundPublishedSnapshotServiceNotifier _backgroundNotifier; + private readonly BackgroundPublishedSnapshotNotifier _backgroundNotifier; public UmbracoInjectedModule( IGlobalSettings globalSettings, @@ -62,7 +63,7 @@ namespace Umbraco.Web IPublishedRouter publishedRouter, IVariationContextAccessor variationContextAccessor, IUmbracoContextFactory umbracoContextFactory, - BackgroundPublishedSnapshotServiceNotifier backgroundNotifier) + BackgroundPublishedSnapshotNotifier backgroundNotifier) { _combinedRouteCollection = new Lazy(CreateRouteCollection); @@ -141,8 +142,19 @@ namespace Umbraco.Web var isRoutableAttempt = EnsureUmbracoRoutablePage(umbracoContext, httpContext); // If this page is probably front-end routable, block here until the backround notifier isn't busy - if (isRoutableAttempt) - _backgroundNotifier.Wait(); + if (isRoutableAttempt) + { + //wait for the notifier to complete if it's in progress + if (_backgroundNotifier.Wait()) + { + // if we were waiting, we need to resync the snapshot + // TODO: This does not belong here! BUT we cannot Resync the snapshot on the background process because there is no snapshot... + // normally it would do that automatically but on a background thread it is null ... hrm.... + ((PublishedSnapshot)_publishedSnapshotService.PublishedSnapshotAccessor.PublishedSnapshot)?.Resync(); + var done = "done"; + } + } + // raise event here UmbracoModule.OnRouteAttempt(this, new RoutableAttemptEventArgs(isRoutableAttempt.Result, umbracoContext, httpContext));