protected function RenderCache::createCacheID in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Render/RenderCache.php \Drupal\Core\Render\RenderCache::createCacheID()
- 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.
File
- core/
lib/ Drupal/ Core/ Render/ RenderCache.php, line 308
Class
- RenderCache
- Wraps the caching logic for the render caching system.
Namespace
Drupal\Core\RenderCode
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;
}