You are here

public function RenderCache::get in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 67
Contains \Drupal\Core\Render\RenderCache.

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;
}