Skip to content

Conversation

@AndyButland
Copy link
Contributor

@AndyButland AndyButland commented Oct 24, 2025

Prerequisites

  • I have added steps to test this contribution in the description below

Resolves #20539 and #20630

Description

This PR fixes a couple of regression issues in 16.3 related to state data being retrieved from the cache.

The first issue manifests itself with the retrieval of a published content item in a content published notification handler. The issue reporter has described it well, diagnosed and suggested the fix I've used here. The regression has come about with the introduction of a micro-optimization around constructing IPublishedContent instances from the cached models in #19990.

With the cache key taking in the version as well as the content ID, we can benefit from the cache for page rendering without incurring this issue in the notification handler.

Issue two shows that if a package that creates content is installed at the same time as Umbraco itself, the created content is not visible on the front-end until a restart of a memory cache reload is carried out. This is happening due to #20209, which is another performance improvement we've added to cache null values for content.

To resolve this one I've ensured the memory cache is cleared following an installation that has run package upgrades. This way we again keep the runtime performance benefit introduced by this behaviour change.

Finally in passing I've improved an installation warning message that occurs (changes the display of "0" to "None", which is more meaningful).

Testing

To test the first issue, create and register a notification handler like the following:

using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models.PublishedContent;
using Umbraco.Cms.Core.Notifications;

namespace Umbraco.Cms.Web.UI.Custom;

public class ContentPublishedNotificationHandler : INotificationHandler<ContentPublishedNotification>
{
    private readonly ILogger<ContentPublishedNotification> _logger;
    private readonly IPublishedContentQuery _publishedContentQuery;

    public ContentPublishedNotificationHandler(ILogger<ContentPublishedNotification> logger, IPublishedContentQuery publishedContentQuery)
    {
        _logger = logger;
        _publishedContentQuery = publishedContentQuery;
    }

    public void Handle(ContentPublishedNotification notification)
    {
        foreach (Core.Models.IContent entity in notification.PublishedEntities)
        {
            _logger.LogInformation($"Published content: {entity.Name} ({entity.Id})");

            IPublishedContent? publishedContent = _publishedContentQuery.Content(entity.Id);
            _logger.LogInformation(publishedContent is null
                ? $"No published content found for ID {entity.Id}."
                : $"Published content retrieved: {publishedContent.Name} ({publishedContent.Id})");
        }
    }
}

Then publish a document, changing it's name.

Before this fix, you will see the old name in the second message that uses the IPublishedContent instance. With the fix in place you'll see the correct, new name.

You can also verify that the cache benefit on page rendering remains by running with logging at Debug level (or temporarily amending the log messages in PublishedContentFactory.ToIPublishedContent to be Information level) and noting that for a given content item on a page render it's only constructed the first time.

For the second issue, configure Umbraco.Web.UI.csproj to have a package reference to:

<PackageReference Include="Clean" Version="6.0.1" />

And start up Umbraco.

Before the fix you'll find that you'll get a 404 on the home page. After this update you'll see the home page content as expected.

Copilot AI review requested due to automatic review settings October 24, 2025 10:04
Copy link
Contributor

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 resolves two critical caching regression issues introduced in version 16.3 that affect published content retrieval and package installation workflows.

Key Changes:

  • Modified cache key generation to include version date, ensuring content published notification handlers receive the latest published content rather than stale cached versions
  • Added cache invalidation after package installation migrations to ensure newly created content is immediately visible on the front-end
  • Improved logging message for serializer warnings by displaying "None" instead of "0"

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
PublishedContentFactory.cs Updated cache key to include version date ticks, preventing retrieval of stale cached content in notification handlers while maintaining performance benefits
DatabaseCacheRebuilder.cs Enhanced logging output to display "None" instead of "0" for missing serializer configuration
MigrationPlansExecutedNotificationHandler.cs New notification handler that clears distributed cache after migration execution to ensure package-created content is visible
UmbracoBuilder.Installer.cs Registered the new MigrationPlansExecutedNotificationHandler to wire up cache invalidation logic

…icationHandler.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant