From 132893deb168ccb9dfb033bd2203690883b4fc1f Mon Sep 17 00:00:00 2001 From: Kristiaan Van den Eynde Date: Mon, 15 Apr 2019 13:43:04 +0200 Subject: [PATCH] interdiff --- core/lib/Drupal/Core/Render/RenderCache.php | 40 ++++++++++++--------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/core/lib/Drupal/Core/Render/RenderCache.php b/core/lib/Drupal/Core/Render/RenderCache.php index 873d680c65..c425cfa44a 100644 --- a/core/lib/Drupal/Core/Render/RenderCache.php +++ b/core/lib/Drupal/Core/Render/RenderCache.php @@ -83,12 +83,20 @@ public function get(array $elements) { // have an accurate representation of its cache tags or max-age. Both // might have changed during the folding of cache contexts, but its not // the variation cache's job to update the thing it's supposed to cache. - // Given how we rely on the '#cache' key to be accurate, we update it with - // the cache metadata from the cache. - $cacheability = CacheableMetadata::createFromRenderArray($cached_element); - $cacheability->addCacheTags($cache->tags); - $cacheability->mergeCacheMaxAge($this->expireToMaxAge($cache->expire)); - $cacheability->applyTo($cached_element); + // + // Given how we rely on the element's '#cache' key to be an accurate + // representation of how the element is cached, we update the element with + // the cache metadata from the cache object as that's where the tags and + // max-age might have changed while setting the cache object. + // + // We also need to remove the 'rendered' cache tag as that one is internal + // to the render cache and shouldn't have come from the actual element. + $cache_tags = $cache->tags; + if (($key = array_search('rendered', $cache_tags, TRUE)) !== FALSE) { + unset($cache_tags[$key]); + } + $cached_element['#cache']['tags'] = $cache_tags; + $cached_element['#cache']['max-age'] = $this->expireToMaxAge($cache->expire); // Return the cached element. return $cached_element; @@ -148,11 +156,11 @@ public function set(array &$elements, array $pre_bubbling_elements) { // ], // ] // - // This efficiently lets cacheGet() redirect to a $cid that includes all - // of the required contexts. The strategy is on-demand: in the case where - // there aren't any additional contexts required by children that aren't - // already included in the parent's pre-bubbled #cache information, no - // cache redirection is needed. + // This efficiently lets get() redirect to a $cid that includes all of the + // required contexts. The strategy is on-demand: in the case where there + // aren't any additional contexts required by children that aren't already + // included in the parent's pre-bubbled #cache information, no cache + // redirection is needed. // // When implementing this redirection strategy, special care is needed to // resolve potential cache ping-pong problems. For example, consider the @@ -246,14 +254,14 @@ public function set(array &$elements, array $pre_bubbling_elements) { // redirect, because the last update's max-age would always "win".) $redirect_cacheability_updated = CacheableMetadata::createFromRenderArray($data)->merge($redirect_cacheability); + // Manipulate the post-bubbling cache keys so that we store the cache + // redirect at the original cache keys' entry and the actual post-bubbling + // element at the manipulated cache keys' entry. + array_unshift($element_cache_keys, 'render_cache_redirect'); + // Stored cache contexts incomplete: this request causes cache contexts to // be added to the redirecting cache item. if (array_diff($redirect_cacheability_updated->getCacheContexts(), $redirect_cacheability->getCacheContexts())) { - // Manipulate the post-bubbling cache keys so that we store the cache - // redirect at the original cache keys' entry and the actual - // post-bubbling element at the manipulated cache keys' entry. - array_unshift($element_cache_keys, 'render_cache_redirect'); - $redirect_data = [ '#cache_redirect' => TRUE, '#cache' => [ -- 2.17.1