protected function RenderCache::createCacheID

protected RenderCache::createCacheID(array &$elements)

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.

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!RenderCache.php/function/RenderCache::createCacheID/8.1.x