From 5c7bf075e66e154a038c78d5cfd3f07c27cfc4a5 Mon Sep 17 00:00:00 2001 From: Paul Johnson Date: Thu, 12 Aug 2021 19:28:48 +0100 Subject: [PATCH 1/2] Backport fix for #10774 to v8 Call EnsureCaches on all notify handlers in PublishedSnapshotService. No need to delete NuCache database files. --- .../NuCache/PublishedSnapshotService.cs | 50 ++----------------- 1 file changed, 5 insertions(+), 45 deletions(-) diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs index 73d06db12b..0e98112fc1 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs @@ -347,28 +347,6 @@ namespace Umbraco.Web.PublishedCache.NuCache return path; } - private void DeleteLocalFilesForContent() - { - if (_isReady && _localContentDb != null) - throw new InvalidOperationException("Cannot delete local files while the cache uses them."); - - var path = GetLocalFilesPath(); - var localContentDbPath = Path.Combine(path, "NuCache.Content.db"); - if (File.Exists(localContentDbPath)) - File.Delete(localContentDbPath); - } - - private void DeleteLocalFilesForMedia() - { - if (_isReady && _localMediaDb != null) - throw new InvalidOperationException("Cannot delete local files while the cache uses them."); - - var path = GetLocalFilesPath(); - var localMediaDbPath = Path.Combine(path, "NuCache.Media.db"); - if (File.Exists(localMediaDbPath)) - File.Delete(localMediaDbPath); - } - #endregion #region Environment @@ -685,13 +663,7 @@ namespace Umbraco.Web.PublishedCache.NuCache public override void Notify(ContentCacheRefresher.JsonPayload[] payloads, out bool draftChanged, out bool publishedChanged) { - // no cache, trash everything - if (_isReady == false) - { - DeleteLocalFilesForContent(); - draftChanged = publishedChanged = true; - return; - } + EnsureCaches(); using (_contentStore.GetScopedWriteLock(_scopeProvider)) { @@ -785,13 +757,7 @@ namespace Umbraco.Web.PublishedCache.NuCache /// public override void Notify(MediaCacheRefresher.JsonPayload[] payloads, out bool anythingChanged) { - // no cache, trash everything - if (_isReady == false) - { - DeleteLocalFilesForMedia(); - anythingChanged = true; - return; - } + EnsureCaches(); using (_mediaStore.GetScopedWriteLock(_scopeProvider)) { @@ -878,9 +844,7 @@ namespace Umbraco.Web.PublishedCache.NuCache /// public override void Notify(ContentTypeCacheRefresher.JsonPayload[] payloads) { - // no cache, nothing we can do - if (_isReady == false) - return; + EnsureCaches(); foreach (var payload in payloads) _logger.Debug("Notified {ChangeTypes} for {ItemType} {ItemId}", payload.ChangeTypes, payload.ItemType, payload.Id); @@ -960,9 +924,7 @@ namespace Umbraco.Web.PublishedCache.NuCache public override void Notify(DataTypeCacheRefresher.JsonPayload[] payloads) { - // no cache, nothing we can do - if (_isReady == false) - return; + EnsureCaches(); var idsA = payloads.Select(x => x.Id).ToArray(); @@ -1000,9 +962,7 @@ namespace Umbraco.Web.PublishedCache.NuCache public override void Notify(DomainCacheRefresher.JsonPayload[] payloads) { - // no cache, nothing we can do - if (_isReady == false) - return; + EnsureCaches(); // see note in LockAndLoadContent using (_domainStore.GetScopedWriteLock(_scopeProvider)) From e869ba7e9bc8f4a4e2c384128618a278a7126cab Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 23 Aug 2021 14:41:26 -0600 Subject: [PATCH 2/2] removes comment --- .../NuCache/PublishedSnapshotService.cs | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs index 0e98112fc1..7a07dcf051 100644 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs @@ -638,25 +638,6 @@ namespace Umbraco.Web.PublishedCache.NuCache #region Handle Notifications - // note: if the service is not ready, ie _isReady is false, then notifications are ignored - - // SetUmbracoVersionStep issues a DistributedCache.Instance.RefreshAll...() call which should cause - // the entire content, media etc caches to reload from database -- and then the app restarts -- however, - // at the time SetUmbracoVersionStep runs, Umbraco is not fully initialized and therefore some property - // value converters, etc are not registered, and rebuilding the NuCache may not work properly. - // - // More details: ApplicationContext.IsConfigured being false, ApplicationEventHandler.ExecuteWhen... is - // called and in most cases events are skipped, so property value converters are not registered or - // removed, so PublishedPropertyType either initializes with the wrong converter, or throws because it - // detects more than one converter for a property type. - // - // It's not an issue for XmlStore - the app restart takes place *after* the install has refreshed the - // cache, and XmlStore just writes a new umbraco.config file upon RefreshAll, so that's OK. - // - // But for NuCache... we cannot rebuild the cache now. So it will NOT work and we are not fixing it, - // because now we should ALWAYS run with the database server messenger, and then the RefreshAll will - // be processed as soon as we are configured and the messenger processes instructions. - // note: notifications for content type and data type changes should be invoked with the // pure live model factory, if any, locked and refreshed - see ContentTypeCacheRefresher and // DataTypeCacheRefresher