Skip to content

Commit ddffd6e

Browse files
AndyButlandclaudeCopilot
authored
HybridCache: Optimize content type change cache rebuild to resolve SQL timeouts (#21207)
* Complete the scope when no runnable job found. Without this I'm seeing timeouts and lock contention if a long-running document type save operation is running when the first distributed job is requested. * Run serialization steps of rebuild of content cache in parallel for a small but not insignficant speed optimization. * Add integration tests for database cache rebuild. * Optimize rebuild of databaes and memory cache after content type update. * Add debug log for running distributed job. * Apply memory cache clear optimization to media. * Optimize MediaCacheService.RebuildMemoryCacheByContentTypeAsync with lightweight query Use GetMediaKeysByContentTypeKeys to fetch only media keys instead of loading full ContentCacheNode objects. This matches the same optimization applied to DocumentCacheService. Also refactors Rebuild() to reuse RebuildMemoryCacheByContentTypeAsync for the memory cache clearing step. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Further updates from code review. * Further tests for variant documents, composed documents and message pack serialization. * Fixed failing integration tests. * Clear the cacje level published content cache on content type change. --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent e206f26 commit ddffd6e

12 files changed

Lines changed: 1993 additions & 206 deletions

File tree

src/Umbraco.Infrastructure/Services/Implement/DistributedJobService.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.Extensions.DependencyInjection;
1+
using Microsoft.Extensions.DependencyInjection;
22
using Microsoft.Extensions.Logging;
33
using Microsoft.Extensions.Options;
44
using Umbraco.Cms.Core;
@@ -69,21 +69,25 @@ public DistributedJobService(
6969
if (job is null)
7070
{
7171
// No runnable jobs for now.
72+
scope.Complete();
7273
return null;
7374
}
7475

7576
job.LastAttemptedRun = DateTime.UtcNow;
7677
job.IsRunning = true;
7778
_distributedJobRepository.Update(job);
79+
scope.Complete();
7880

7981
IDistributedBackgroundJob? distributedJob = _distributedBackgroundJobs.FirstOrDefault(x => x.Name == job.Name);
8082

8183
if (distributedJob is null)
8284
{
8385
_logger.LogWarning("Could not find a distributed job with the name '{JobName}'", job.Name);
8486
}
85-
86-
scope.Complete();
87+
else
88+
{
89+
_logger.LogDebug("Running distributed job with the name '{JobName}'", job.Name);
90+
}
8791

8892
return distributedJob;
8993
}

src/Umbraco.Infrastructure/Umbraco.Infrastructure.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
</ItemGroup>
7171

7272
<ItemGroup>
73+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
74+
<_Parameter1>Umbraco.PublishedCache.HybridCache</_Parameter1>
75+
</AssemblyAttribute>
7376
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
7477
<_Parameter1>Umbraco.Tests</_Parameter1>
7578
</AssemblyAttribute>
@@ -88,8 +91,5 @@
8891
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
8992
<_Parameter1>DynamicProxyGenAssembly2</_Parameter1>
9093
</AssemblyAttribute>
91-
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
92-
<_Parameter1>Umbraco.Cms.Infrastructure</_Parameter1>
93-
</AssemblyAttribute>
9494
</ItemGroup>
9595
</Project>

0 commit comments

Comments
 (0)