core/lib/Drupal/Core/Render/RenderCache.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/lib/Drupal/Core/Render/RenderCache.php b/core/lib/Drupal/Core/Render/RenderCache.php index e2b0276..1a8339b 100644 --- a/core/lib/Drupal/Core/Render/RenderCache.php +++ b/core/lib/Drupal/Core/Render/RenderCache.php @@ -215,7 +215,15 @@ public function set(array &$elements, array $pre_bubbling_elements) { } // Calculate the union of the cacheability for this request and the - // current (stored) redirecting cache item. + // current (stored) redirecting cache item. We need: + // - the union of cache contexts, because that is how we know which cache + // item to redirect to; + // - the union of cache tags, because that is how we know when the cache + // redirect cache item itself is invalidated; + // - the union of max ages, because that is how we know when the cache + // redirect cache item itself becomes stale. (Without this, we might end + // up toggling between a permanently and a briefly cacheable cache + // redirect, because the last update's max-age would always "win".) $redirect_cacheability_updated = CacheableMetadata::createFromRenderArray($data)->merge($redirect_cacheability); // Stored cache contexts incomplete: this request causes cache contexts to