function RenderCache::set

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

Overrides RenderCacheInterface::set

1 call to RenderCache::set()
PlaceholderingRenderCache::set in core/lib/Drupal/Core/Render/PlaceholderingRenderCache.php
Caches the rendered output of a renderable array.
1 method overrides RenderCache::set()
PlaceholderingRenderCache::set in core/lib/Drupal/Core/Render/PlaceholderingRenderCache.php
Caches the rendered output of a renderable array.

File

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

Class

RenderCache
Wraps the caching logic for the render caching system.

Namespace

Drupal\Core\Render

Code

public function set(array &$elements, array $pre_bubbling_elements) {
    // Avoid setting cache items on POST requests, this ensures that cache items
    // with a very low hit rate won't enter the cache. All render elements
    // except forms will still be retrieved from cache when available.
    if (!$this->requestStack
        ->getCurrentRequest()
        ->isMethodCacheable() || !$this->isElementCacheable($elements)) {
        return FALSE;
    }
    $bin = $elements['#cache']['bin'] ?? 'render';
    $cache_bin = $this->cacheFactory
        ->get($bin);
    $data = $this->getCacheableRenderArray($elements);
    $cache_bin->set($elements['#cache']['keys'], $data, CacheableMetadata::createFromRenderArray($data)->addCacheTags([
        'rendered',
    ]), CacheableMetadata::createFromRenderArray($pre_bubbling_elements));
}

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