Adds variation by the header name Accept-Language to the delivery API output cache policy#19709
Merged
AndyButland merged 3 commits intov13/devfrom Jul 11, 2025
Conversation
…PI output cache policy
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the Delivery API’s output caching by varying cached responses based on the Accept-Language and Start-Item headers, ensuring different languages don’t share the same cache entry.
- Added
StringValuesimport and new constructor to accept header names inDeliveryApiOutputCachePolicy - Updated
AddOutputCacheto pass header names for content and media caching policies - Modified
CacheRequestAsyncto apply the header-based vary rules
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Umbraco.Cms.Api.Delivery/DependencyInjection/UmbracoBuilderExtensions.cs | Imported StringValues and updated AddOutputCache to pass header names for both content and media caching policies |
| src/Umbraco.Cms.Api.Delivery/Caching/DeliveryApiOutputCachePolicy.cs | Introduced a new constructor overload accepting StringValues and applied the header names to CacheVaryByRules.HeaderNames in CacheRequestAsync |
Comments suppressed due to low confidence (2)
src/Umbraco.Cms.Api.Delivery/DependencyInjection/UmbracoBuilderExtensions.cs:112
- Consider adding a unit or integration test that sends requests with different
Accept-Languageheaders to verify the output cache varies as expected and does not return the same cached response.
options.AddPolicy(Constants.DeliveryApi.OutputCache.ContentCachePolicy, new DeliveryApiOutputCachePolicy(outputCacheSettings.ContentDuration, new StringValues(["Accept-Language", "Start-Item"])));
src/Umbraco.Cms.Api.Delivery/DependencyInjection/UmbracoBuilderExtensions.cs:112
- The array literal syntax
new StringValues(["Accept-Language", "Start-Item"])is invalid C#. Use eithernew StringValues(new[] { "Accept-Language", "Start-Item" })or the params-based constructor:new StringValues("Accept-Language", "Start-Item").
options.AddPolicy(Constants.DeliveryApi.OutputCache.ContentCachePolicy, new DeliveryApiOutputCachePolicy(outputCacheSettings.ContentDuration, new StringValues(["Accept-Language", "Start-Item"])));
src/Umbraco.Cms.Api.Delivery/DependencyInjection/UmbracoBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
src/Umbraco.Cms.Api.Delivery/DependencyInjection/UmbracoBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
lauraneto
approved these changes
Jul 11, 2025
AndyButland
added a commit
that referenced
this pull request
Jul 11, 2025
… output cache policy (#19709) * Adds variation by the header name Accept-Language to the develivery API output cache policy * Removed obsolete constructor (not necessary as the class is internal). * Introduce contants for header names.
Contributor
Author
|
Merged for 13 and cherry-picked over to |
This was referenced Dec 9, 2025
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
Resolves: #19706
Description
The delivery API output cache isn't varying over the accepted headers, leading to the problem described in the linked issue.
This PR adjusts the policy to vary over the headers that could be used for the document and media requests are included in the collection of details to vary by.
Note that "Preview" isn't necessary to include as preview requests aren't cached anyway.
Testing
See the linked issue. Note that once the PR is applied the request for the same item by different languages is not cached such that each language can be retrieved.
Confirm that output caching still works by modifying the content item and note that the old values are retrieved until the cache time expires.
Merge and Release
When merged this will be part of 13.10, but should also be cherry-picked up for 16.2.
When porting to 16, include "Accept-Segment" in the constants.