function RenderCache::get

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/RenderCache.php \Drupal\Core\Render\RenderCache::get()
  2. 10 core/lib/Drupal/Core/Render/RenderCache.php \Drupal\Core\Render\RenderCache::get()
  3. 11.x core/lib/Drupal/Core/Render/RenderCache.php \Drupal\Core\Render\RenderCache::get()

Overrides RenderCacheInterface::get

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.