function RenderCache::get

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Render/RenderCache.php \Drupal\Core\Render\RenderCache::get()
  2. 8.9.x core/lib/Drupal/Core/Render/RenderCache.php \Drupal\Core\Render\RenderCache::get()
  3. 10 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

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 37

Class

RenderCache
Wraps the caching logic for the render caching system.

Namespace

Drupal\Core\Render

Code

public function get(array $elements) {
  // This method uses a different approach compared to ::getMultiple(), as it
  // is designed for fetching a single item efficiently.
  if (!$this->isElementCacheable($elements)) {
    return FALSE;
  }
  $cache_bin = $this->cacheFactory
    ->get($elements['#cache']['bin'] ?? 'render');
  if ($cache = $cache_bin->get($elements['#cache']['keys'], CacheableMetadata::createFromRenderArray($elements))) {
    if (!$this->isCacheableForCurrentHttpMethod($cache->tags)) {
      return FALSE;
    }
    return $cache->data;
  }
  return FALSE;
}

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