RenderCache::get

public RenderCache::get(array $elements)

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()

File

core/lib/Drupal/Core/Render/RenderCache.php, line 61

Class

RenderCache
Wraps the caching logic for the render caching system.

Namespace

Drupal\Core\Render

Code

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 isMethodSafe() check when
  //       https://www.drupal.org/node/2367555 lands.
  if (!$this->requestStack->getCurrentRequest()->isMethodSafe() || !$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;
}
doc_Drupal
2016-10-29 09:37:27
Comments
Leave a Comment

Please login to continue.