diff --git a/src/Umbraco.Core/PublishedCache/IPublishedSnapshotService.cs b/src/Umbraco.Core/PublishedCache/IPublishedSnapshotService.cs index f8d158dce9..5bd5ff23cc 100644 --- a/src/Umbraco.Core/PublishedCache/IPublishedSnapshotService.cs +++ b/src/Umbraco.Core/PublishedCache/IPublishedSnapshotService.cs @@ -61,6 +61,22 @@ public interface IPublishedSnapshotService : IDisposable IReadOnlyCollection? mediaTypeIds = null, IReadOnlyCollection? memberTypeIds = null); + + /// + /// Rebuilds all internal database caches (but does not reload). + /// + /// + /// + /// Forces the snapshot service to rebuild its internal database caches. For instance, some caches + /// may rely on a database table to store pre-serialized version of documents. + /// + /// + /// This does *not* reload the caches. Caches need to be reloaded, for instance via + /// RefreshAllPublishedSnapshot method. + /// + /// + void RebuildAll() => Rebuild(Array.Empty(), Array.Empty(), Array.Empty()); + /* An IPublishedCachesService implementation can rely on transaction-level events to update * its internal, database-level data, as these events are purely internal. However, it cannot * rely on cache refreshers CacheUpdated events to update itself, as these events are external diff --git a/src/Umbraco.Infrastructure/Migrations/PostMigrations/PublishedSnapshotRebuilder.cs b/src/Umbraco.Infrastructure/Migrations/PostMigrations/PublishedSnapshotRebuilder.cs index f70fd0ddb3..d86307b1f9 100644 --- a/src/Umbraco.Infrastructure/Migrations/PostMigrations/PublishedSnapshotRebuilder.cs +++ b/src/Umbraco.Infrastructure/Migrations/PostMigrations/PublishedSnapshotRebuilder.cs @@ -26,7 +26,7 @@ public class PublishedSnapshotRebuilder : IPublishedSnapshotRebuilder /// public void Rebuild() { - _publishedSnapshotService.Rebuild(); + _publishedSnapshotService.RebuildAll(); _distributedCache.RefreshAllPublishedSnapshot(); } } diff --git a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs index 176a664d42..cb4439f2ae 100644 --- a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs +++ b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentRepository.cs @@ -97,6 +97,7 @@ public class NuCacheContentRepository : RepositoryBase, INuCacheContentRepositor OnRepositoryRefreshed(serializer, member, false); } + /// public void Rebuild( IReadOnlyCollection? contentTypeIds = null, IReadOnlyCollection? mediaTypeIds = null, @@ -107,9 +108,20 @@ public class NuCacheContentRepository : RepositoryBase, INuCacheContentRepositor | ContentCacheDataSerializerEntityType.Media | ContentCacheDataSerializerEntityType.Member); - RebuildContentDbCache(serializer, _nucacheSettings.Value.SqlPageSize, contentTypeIds); - RebuildMediaDbCache(serializer, _nucacheSettings.Value.SqlPageSize, mediaTypeIds); - RebuildMemberDbCache(serializer, _nucacheSettings.Value.SqlPageSize, memberTypeIds); + if(contentTypeIds != null) + { + RebuildContentDbCache(serializer, _nucacheSettings.Value.SqlPageSize, contentTypeIds); + } + + if (mediaTypeIds != null) + { + RebuildMediaDbCache(serializer, _nucacheSettings.Value.SqlPageSize, mediaTypeIds); + } + + if (memberTypeIds != null) + { + RebuildMemberDbCache(serializer, _nucacheSettings.Value.SqlPageSize, memberTypeIds); + } } // assumes content tree lock diff --git a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentService.cs b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentService.cs index 3aa071716e..09855f5682 100644 --- a/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentService.cs +++ b/src/Umbraco.PublishedCache.NuCache/Persistence/NuCacheContentService.cs @@ -51,7 +51,7 @@ public class NuCacheContentService : RepositoryService, INuCacheContentService using (_profilingLogger.TraceDuration( $"Rebuilding NuCache database with {serializer} serializer")) { - Rebuild(); + RebuildAll(); _keyValueService.SetValue(NuCacheSerializerKey, serializer.ToString()); } } @@ -113,11 +113,17 @@ public class NuCacheContentService : RepositoryService, INuCacheContentService public void RefreshMember(IMember member) => _repository.RefreshMember(member); + /// + public void RebuildAll() + { + Rebuild(Array.Empty(), Array.Empty(), Array.Empty()); + } + /// public void Rebuild( - IReadOnlyCollection? contentTypeIds = null, - IReadOnlyCollection? mediaTypeIds = null, - IReadOnlyCollection? memberTypeIds = null) + IReadOnlyCollection? contentTypeIds = null, + IReadOnlyCollection? mediaTypeIds = null, + IReadOnlyCollection? memberTypeIds = null) { using (ICoreScope scope = ScopeProvider.CreateCoreScope(repositoryCacheMode: RepositoryCacheMode.Scoped)) { diff --git a/src/Umbraco.Web.BackOffice/Controllers/PublishedSnapshotCacheStatusController.cs b/src/Umbraco.Web.BackOffice/Controllers/PublishedSnapshotCacheStatusController.cs index 9980089248..c8c391d990 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/PublishedSnapshotCacheStatusController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/PublishedSnapshotCacheStatusController.cs @@ -34,7 +34,8 @@ public class PublishedSnapshotCacheStatusController : UmbracoAuthorizedApiContro [HttpPost] public string RebuildDbCache() { - _publishedSnapshotService.Rebuild(); + //Rebuild All + _publishedSnapshotService.RebuildAll(); return _publishedSnapshotStatus.GetStatus(); } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/NuCacheRebuildTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/NuCacheRebuildTests.cs index ed0c7ac264..5604419623 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/NuCacheRebuildTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/NuCacheRebuildTests.cs @@ -1,3 +1,4 @@ +using System; using NUnit.Framework; using Umbraco.Cms.Core; using Umbraco.Cms.Core.PublishedCache; @@ -59,7 +60,7 @@ public class NuCacheRebuildTests : UmbracoIntegrationTest Assert.AreEqual("hello", segment); - PublishedSnapshotService.Rebuild(); + PublishedSnapshotService.RebuildAll(); cachedContent = ContentService.GetById(content.Id); segment = urlSegmentProvider.GetUrlSegment(cachedContent); @@ -76,7 +77,7 @@ public class NuCacheRebuildTests : UmbracoIntegrationTest // The page has now been published, so we should see the new url segment Assert.AreEqual("goodbye", segment); - PublishedSnapshotService.Rebuild(); + PublishedSnapshotService.RebuildAll(); cachedContent = ContentService.GetById(content.Id); segment = urlSegmentProvider.GetUrlSegment(cachedContent);