Skip to content

Move cache instructions pruning to background job #19598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

lauraneto
Copy link
Contributor

@lauraneto lauraneto commented Jun 23, 2025

Description

Moves the cache instructions pruning from the CacheInstructionService.ProcessInstructions() method to a new CacheInstructionsPruningJob background job.

Testing

Make sure that the instructions are still pruned as expected, by checking the umbracoCacheInstruction database table.
To help with testing, adjust the following app settings to lower values:

"Umbraco": {
  "CMS": {
    ..
    "Global": {
      ...
      "DatabaseServerMessenger": {
        "TimeBetweenPruneOperations": "0:00:30",
        "TimeToRetainInstructions": "0:05:00"
      }
    },
  }
}

This should make it so that the job will run every 30 seconds, and will delete all instructions older than 5 minutes (always leaving at least 1).
Be aware that there is a default delay of 3 minutes (default) from startup to when the background job actually starts running.

@lauraneto lauraneto marked this pull request as ready for review June 24, 2025 11:28
@Copilot Copilot AI review requested due to automatic review settings June 24, 2025 11:28
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR extracts cache instruction pruning from the CacheInstructionService and shifts it into a dedicated CacheInstructionsPruningJob, cleaning up obsolete methods and constructors and updating registrations and tests accordingly.

  • Introduces CacheInstructionsPruningJob and registers it as a recurring background job.
  • Removes pruning logic and related overloads from CacheInstructionService and DatabaseServerMessenger.
  • Updates unit and integration tests to call the new ProcessInstructions overload and remove assertions around pruning.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/.../CacheInstructionsPruningJobTests.cs Adds unit tests for the new pruning job’s period and run logic
tests/.../CacheInstructionServiceTests.cs (Integration) Updates calls to ProcessInstructions and removes pruning tests
src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs Registers CacheInstructionsPruningJob
src/Umbraco.Infrastructure/Sync/DatabaseServerMessenger.cs Removes server-role–based pruning and obsolete fields
src/Umbraco.Infrastructure/Sync/BatchedDatabaseServerMessenger.cs Adds new constructor, marks old one obsolete
src/Umbraco.Infrastructure/Services/CacheInstructionService.cs Removes inline pruning logic and obsolete overload
src/Umbraco.Infrastructure/BackgroundJobs/Jobs/CacheInstructionsPruningJob.cs Adds the new background job implementation
src/Umbraco.Core/Services/ProcessInstructionsResult.cs Marks pruning flag and related factory as obsolete
src/Umbraco.Core/Services/ICacheInstructionService.cs Adds new overload for ProcessInstructions
Comments suppressed due to low confidence (2)

src/Umbraco.Core/Services/ICacheInstructionService.cs:37

  • The summary for the new ProcessInstructions overload still mentions pruning, but pruning now happens in a background job. Update the XML comment to reflect that this overload only processes instructions.
    ///     Processes and then prunes pending database cache instructions.

src/Umbraco.Infrastructure/Sync/BatchedDatabaseServerMessenger.cs:54

  • The obsolete constructor takes an IRequestAccessor requestAccessor but calls this(..., requestCache, ...). The requestCache parameter isn't in scope and will not compile. Include IRequestCache requestCache in the obsolete signature or pass the correct parameter.
    public BatchedDatabaseServerMessenger(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant