function RenderCache::createCacheID

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/RenderCache.php \Drupal\Core\Render\RenderCache::createCacheID()

Creates the cache ID for a renderable element.

Creates the cache ID string based on #cache['keys'] + #cache['contexts'].

Parameters

array &$elements: A renderable array.

Return value

string The cache ID string, or FALSE if the element may not be cached.

2 calls to RenderCache::createCacheID()
RenderCache::get in core/lib/Drupal/Core/Render/RenderCache.php
Gets the cached, pre-rendered element of a renderable element from cache.
RenderCache::set in core/lib/Drupal/Core/Render/RenderCache.php
Caches the rendered output of a renderable array.

File

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

Class

RenderCache
Wraps the caching logic for the render caching system.

Namespace

Drupal\Core\Render

Code

protected function createCacheID(array &$elements) {
    // If the maximum age is zero, then caching is effectively prohibited.
    if (isset($elements['#cache']['max-age']) && $elements['#cache']['max-age'] === 0) {
        return FALSE;
    }
    if (isset($elements['#cache']['keys'])) {
        $cid_parts = $elements['#cache']['keys'];
        if (!empty($elements['#cache']['contexts'])) {
            $context_cache_keys = $this->cacheContextsManager
                ->convertTokensToKeys($elements['#cache']['contexts']);
            $cid_parts = array_merge($cid_parts, $context_cache_keys->getKeys());
            CacheableMetadata::createFromRenderArray($elements)->merge($context_cache_keys)
                ->applyTo($elements);
        }
        return implode(':', $cid_parts);
    }
    return FALSE;
}

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