Created
February 18, 2015 13:20
-
-
Save LionsAd/fef2568413569c13e952 to your computer and use it in GitHub Desktop.
SmartCache++
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
diff --git a/core/lib/Drupal/Core/Render/Renderer.php b/core/lib/Drupal/Core/Render/Renderer.php | |
index 69e99a0..8bdf86a 100644 | |
--- a/core/lib/Drupal/Core/Render/Renderer.php | |
+++ b/core/lib/Drupal/Core/Render/Renderer.php | |
@@ -184,6 +184,11 @@ protected function doRender(&$elements, $is_root_call = FALSE) { | |
$this->bubbleStack(); | |
return $elements['#markup']; | |
} | |
+ | |
+ // Store the cache ID for later comparison. | |
+ if ($this->requestStack->getCurrentRequest()->isMethodSafe() && $cid = $this->createCacheID($elements)) { | |
+ $elements['#cache_old_id'] = $cid; | |
+ } | |
} | |
// If the default values for this element have not been loaded yet, populate | |
@@ -493,6 +498,9 @@ protected function cacheGet(array $elements) { | |
if (!empty($cid) && $cache = $this->cacheFactory->get($bin)->get($cid)) { | |
$cached_element = $cache->data; | |
+ if (isset($cached_element['#cache_try_again'])) { | |
+ return $this->cacheGet($cached_element); | |
+ } | |
// Return the cached element. | |
return $cached_element; | |
} | |
@@ -530,7 +538,17 @@ protected function cacheSet(array &$elements) { | |
$bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'render'; | |
$expire = isset($elements['#cache']['expire']) ? $elements['#cache']['expire'] : Cache::PERMANENT; | |
- $this->cacheFactory->get($bin)->set($cid, $data, $expire, $data['#cache']['tags']); | |
+ $cache = $this->cacheFactory->get($bin); | |
+ | |
+ // This assumes bubbling worked correctly and createCacheID() working on contexts instead of cache keys. | |
+ if (isset($elements['#cache_old_id']) && $cid != $elements['#cache_old_id']) { | |
+ $redir_data = [ | |
+ '#cache_try_again' => TRUE, | |
+ '#cache' => $elements['#cache'], | |
+ ]; | |
+ $cache->set($elements['#cache_old_id'], $redir_data, $expire, $data['#cache']['tags']); | |
+ } | |
+ $cache->set($cid, $data, $expire, $data['#cache']['tags']); | |
} | |
/** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment