public function RenderCache::get in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Render/RenderCache.php \Drupal\Core\Render\RenderCache::get()
Gets the cached, pre-rendered element of a renderable element from cache.
Parameters
array $elements: A renderable array.
Return value
array|false A renderable array, with the original element and all its children pre- rendered, or FALSE if no cached copy of the element is available.
Overrides RenderCacheInterface::get
See also
\Drupal\Core\Render\RendererInterface::render()
::set()
1 call to RenderCache::get()
- PlaceholderingRenderCache::get in core/
lib/ Drupal/ Core/ Render/ PlaceholderingRenderCache.php - Gets the cached, pre-rendered element of a renderable element from cache.
1 method overrides RenderCache::get()
- PlaceholderingRenderCache::get in core/
lib/ Drupal/ Core/ Render/ PlaceholderingRenderCache.php - Gets the cached, pre-rendered element of a renderable element from cache.
File
- core/
lib/ Drupal/ Core/ Render/ RenderCache.php, line 61
Class
- RenderCache
- Wraps the caching logic for the render caching system.
Namespace
Drupal\Core\RenderCode
public function get(array $elements) {
// Form submissions rely on the form being built during the POST request,
// and render caching of forms prevents this from happening.
// @todo remove the isMethodCacheable() check when
// https://www.drupal.org/node/2367555 lands.
if (!$this->requestStack
->getCurrentRequest()
->isMethodCacheable() || !($cid = $this
->createCacheID($elements))) {
return FALSE;
}
$bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'render';
if (!empty($cid) && ($cache_bin = $this->cacheFactory
->get($bin)) && ($cache = $cache_bin
->get($cid))) {
$cached_element = $cache->data;
// Two-tier caching: redirect to actual (post-bubbling) cache item.
// @see \Drupal\Core\Render\RendererInterface::render()
// @see ::set()
if (isset($cached_element['#cache_redirect'])) {
return $this
->get($cached_element);
}
// Return the cached element.
return $cached_element;
}
return FALSE;
}