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. 11.x 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 61

Class

RenderCache
Wraps the caching logic for the render caching system.

Namespace

Drupal\Core\Render

Code

public function get(array $elements) {
  if (!$this->isElementCacheable($elements)) {
    return FALSE;
  }
  $bin = $elements['#cache']['bin'] ?? 'render';
  if (($cache_bin = $this->cacheFactory
    ->get($bin)) && ($cache = $cache_bin->get($elements['#cache']['keys'], CacheableMetadata::createFromRenderArray($elements)))) {
    if (!$this->requestStack
      ->getCurrentRequest()
      ->isMethodCacheable()) {
      if (!empty(array_filter($cache->tags, fn(string $tag) => str_starts_with($tag, 'CACHE_MISS_IF_UNCACHEABLE_HTTP_METHOD:')))) {
        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.