From ca15aadf0ea7492ac4d18a2324f81ec233018a26 Mon Sep 17 00:00:00 2001 From: Justin Neville <67802060+justin-nevitech@users.noreply.github.com> Date: Thu, 13 Nov 2025 00:21:26 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20for=20partial=20view=20caches=20not=20bei?= =?UTF-8?q?ng=20cleared=20when=20content=20is=20publish=E2=80=A6=20(#20794?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix for partial view caches not being cleared when content is published/unpublished * Update src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> * Change logic for clearing partial view cache * Changed logic to only clear partial cache when content is published/unpublished or trashed --------- Co-authored-by: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> --- .../Implement/ContentCacheRefresher.cs | 40 +++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs b/src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs index 7505781ad9..b1307ef1e8 100644 --- a/src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs +++ b/src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs @@ -1,5 +1,3 @@ -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Notifications; @@ -151,6 +149,12 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase 0) { var assignedDomains = _domainService.GetAll(true) @@ -175,6 +179,28 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase + { + // Check for relelvant change type + var isRelevantChangeType = x.ChangeTypes.HasType(TreeChangeTypes.RefreshAll) || + x.ChangeTypes.HasType(TreeChangeTypes.Remove) || + x.ChangeTypes.HasType(TreeChangeTypes.RefreshNode) || + x.ChangeTypes.HasType(TreeChangeTypes.RefreshBranch); + + // Check for published/unpublished changes + var hasChanges = x.PublishedCultures?.Length > 0 || + x.UnpublishedCultures?.Length > 0; + + // There's no other way to detect trashed content as the change type is only Remove when deleted permanently + var isTrashed = x.ChangeTypes.HasType(TreeChangeTypes.RefreshBranch) && x.PublishedCultures is null && x.UnpublishedCultures is null; + + // Skip blueprints and only clear the partial cache for removals or refreshes with changes + return x.Blueprint == false && (isTrashed || (isRelevantChangeType && hasChanges)); + }); + } + private void HandleMemoryCache(JsonPayload payload) { Guid key = payload.Key ?? _idKeyMap.GetKeyForId(payload.Id, UmbracoObjectTypes.Document).Result; @@ -365,7 +391,7 @@ public sealed class ContentCacheRefresher : PayloadCacheRefresherBase