From 05e5803ebaa6330979e9a4ff6a4b343e74957ca0 Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Wed, 17 Sep 2025 21:04:50 +0200 Subject: [PATCH 1/3] Implement initial fix --- .../Services/DocumentCacheService.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.PublishedCache.HybridCache/Services/DocumentCacheService.cs b/src/Umbraco.PublishedCache.HybridCache/Services/DocumentCacheService.cs index 6457773e317a..57827ff86650 100644 --- a/src/Umbraco.PublishedCache.HybridCache/Services/DocumentCacheService.cs +++ b/src/Umbraco.PublishedCache.HybridCache/Services/DocumentCacheService.cs @@ -135,7 +135,11 @@ public DocumentCacheService( // We don't want to cache removed items, this may cause issues if the L2 serializer changes. if (contentCacheNode is null) { - await _hybridCache.RemoveAsync(cacheKey); + // We don't have to remove if it's published, we'll clear this node again if deleted/published + if (preview) + { + await _hybridCache.RemoveAsync(cacheKey); + } return null; } @@ -340,12 +344,9 @@ public async Task RebuildMemoryCacheByContentTypeAsync(IEnumerable contentT foreach (ContentCacheNode content in contentByContentTypeKey) { - _hybridCache.RemoveAsync(GetCacheKey(content.Key, true)).GetAwaiter().GetResult(); - - if (content.IsDraft is false) - { - _hybridCache.RemoveAsync(GetCacheKey(content.Key, false)).GetAwaiter().GetResult(); - } + // Always remove both types of nodes regardless of published status, as we might have cached null values.. + await _hybridCache.RemoveAsync(GetCacheKey(content.Key, true)); + await _hybridCache.RemoveAsync(GetCacheKey(content.Key, false)); } } } From 2d37c0272384347faa3eab5ba6c6a95694241b5e Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Mon, 22 Sep 2025 12:53:57 +0200 Subject: [PATCH 2/3] Revert "Implement initial fix" This reverts commit 05e5803ebaa6330979e9a4ff6a4b343e74957ca0. --- .../Services/DocumentCacheService.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.PublishedCache.HybridCache/Services/DocumentCacheService.cs b/src/Umbraco.PublishedCache.HybridCache/Services/DocumentCacheService.cs index 57827ff86650..6457773e317a 100644 --- a/src/Umbraco.PublishedCache.HybridCache/Services/DocumentCacheService.cs +++ b/src/Umbraco.PublishedCache.HybridCache/Services/DocumentCacheService.cs @@ -135,11 +135,7 @@ public DocumentCacheService( // We don't want to cache removed items, this may cause issues if the L2 serializer changes. if (contentCacheNode is null) { - // We don't have to remove if it's published, we'll clear this node again if deleted/published - if (preview) - { - await _hybridCache.RemoveAsync(cacheKey); - } + await _hybridCache.RemoveAsync(cacheKey); return null; } @@ -344,9 +340,12 @@ public async Task RebuildMemoryCacheByContentTypeAsync(IEnumerable contentT foreach (ContentCacheNode content in contentByContentTypeKey) { - // Always remove both types of nodes regardless of published status, as we might have cached null values.. - await _hybridCache.RemoveAsync(GetCacheKey(content.Key, true)); - await _hybridCache.RemoveAsync(GetCacheKey(content.Key, false)); + _hybridCache.RemoveAsync(GetCacheKey(content.Key, true)).GetAwaiter().GetResult(); + + if (content.IsDraft is false) + { + _hybridCache.RemoveAsync(GetCacheKey(content.Key, false)).GetAwaiter().GetResult(); + } } } } From 605d3f4078f4936ee7ba792e98e4cbd6b640e14e Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Mon, 22 Sep 2025 13:32:08 +0200 Subject: [PATCH 3/3] Don't remove null cache values, they can always get removed when clearing cache --- .../Services/DocumentCacheService.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Umbraco.PublishedCache.HybridCache/Services/DocumentCacheService.cs b/src/Umbraco.PublishedCache.HybridCache/Services/DocumentCacheService.cs index 6457773e317a..2d41bc0a1261 100644 --- a/src/Umbraco.PublishedCache.HybridCache/Services/DocumentCacheService.cs +++ b/src/Umbraco.PublishedCache.HybridCache/Services/DocumentCacheService.cs @@ -132,10 +132,8 @@ public DocumentCacheService( GetEntryOptions(key, preview), GenerateTags(key)); - // We don't want to cache removed items, this may cause issues if the L2 serializer changes. if (contentCacheNode is null) { - await _hybridCache.RemoveAsync(cacheKey); return null; }