Add request caching around published content factory#19990
Merged
nikolajlauridsen merged 3 commits intomainfrom Aug 27, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements request-level caching for the PublishedContentFactory to improve performance by avoiding repeated instantiation of the same IPublishedContent objects within a single request. The cache reduces content instantiation from 35 to 9 instances when loading a product page in the Umbraco starter kit.
- Adds request caching to
ToIPublishedContent,ToIPublishedMedia, andToPublishedMembermethods - Introduces comprehensive integration tests to verify caching behavior
- Adds XML documentation to improve code maintainability
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/Umbraco.PublishedCache.HybridCache/Factories/PublishedContentFactory.cs |
Implements request caching logic and adds comprehensive logging and documentation |
src/Umbraco.PublishedCache.HybridCache/Factories/IPublishedContentFactory.cs |
Adds XML documentation for the interface methods |
tests/Umbraco.Tests.Integration/Umbraco.PublishedCache.HybridCache/Factories/PublishedContentFactoryTests.cs |
New integration test file verifying caching behavior for all factory methods |
src/Umbraco.PublishedCache.HybridCache/Factories/PublishedContentFactory.cs
Outdated
Show resolved
Hide resolved
src/Umbraco.PublishedCache.HybridCache/Factories/PublishedContentFactory.cs
Outdated
Show resolved
Hide resolved
src/Umbraco.PublishedCache.HybridCache/Factories/PublishedContentFactory.cs
Outdated
Show resolved
Hide resolved
src/Umbraco.PublishedCache.HybridCache/Factories/PublishedContentFactory.cs
Outdated
Show resolved
Hide resolved
src/Umbraco.PublishedCache.HybridCache/Factories/PublishedContentFactory.cs
Outdated
Show resolved
Hide resolved
src/Umbraco.PublishedCache.HybridCache/Factories/PublishedContentFactory.cs
Outdated
Show resolved
Hide resolved
bjarnef
reviewed
Aug 25, 2025
src/Umbraco.PublishedCache.HybridCache/Factories/IPublishedContentFactory.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
Contributor
|
Looks good, tests good 👍 I Inverted the if statements to make the code more readable 😄 |
nikolajlauridsen
approved these changes
Aug 27, 2025
1 task
This was referenced Oct 24, 2025
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
Relates to #18892
Description
We've had some discussion on the linked issue and internally about the potential performance concern of having to translate from the object stored into the hybrid cache and the
IPublishedContentinstance. It can be argued if this is likely to be a concern in typical page generation, but, as noted, it seems straightforward to at least request cache this.As such I've applied that in this PR.
Given it's only cached for the request, we don't have to be concerned about cache invalidation.
Looking at a small site - the Umbraco starter kit - it does seem we can instantiate the same
IPublishedContentmultiple times in a single page request.When this update is applied, loading a product page, which has the navigation bar, from the starter kit creates 9
IPublishedContentinstances. Without the request cache, it creates 35.And so this should have a positive, even if often small or even negligible, impact - and I can't see it can cause any harm.
Testing
Verify pages render from the cache as expected.
Using a breakpoint in
PublishedContentFactoryverify that the items are retrieved from the cache on all but the first time for a page request.