function RenderCache::isElementCacheable

Same name and namespace in other branches
  1. 10 core/lib/Drupal/Core/Render/RenderCache.php \Drupal\Core\Render\RenderCache::isElementCacheable()

Checks whether a renderable array can be cached.

This allows us to not even have to instantiate the cache backend if a renderable array does not have any cache keys or specifies a zero cache max age.

Parameters

array $element: A renderable array.

Return value

bool Whether the renderable array is cacheable.

2 calls to RenderCache::isElementCacheable()
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 129

Class

RenderCache
Wraps the caching logic for the render caching system.

Namespace

Drupal\Core\Render

Code

protected function isElementCacheable(array $element) {
    // If the maximum age is zero, then caching is effectively prohibited.
    if (isset($element['#cache']['max-age']) && $element['#cache']['max-age'] === 0) {
        return FALSE;
    }
    return isset($element['#cache']['keys']);
}

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