interface RenderCacheInterface

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Render/RenderCacheInterface.php \Drupal\Core\Render\RenderCacheInterface
  2. 10 core/lib/Drupal/Core/Render/RenderCacheInterface.php \Drupal\Core\Render\RenderCacheInterface
  3. 11.x core/lib/Drupal/Core/Render/RenderCacheInterface.php \Drupal\Core\Render\RenderCacheInterface

Defines an interface for caching rendered render arrays.

@internal

Hierarchy

Expanded class hierarchy of RenderCacheInterface

All classes that implement RenderCacheInterface

See also

sec_caching

\Drupal\Core\Render\RendererInterface

3 files declare their use of RenderCacheInterface
DynamicPageCacheSubscriber.php in core/modules/dynamic_page_cache/src/EventSubscriber/DynamicPageCacheSubscriber.php
HtmlRenderer.php in core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php
ResourceObjectNormalizationCacher.php in core/modules/jsonapi/src/EventSubscriber/ResourceObjectNormalizationCacher.php

File

core/lib/Drupal/Core/Render/RenderCacheInterface.php, line 13

Namespace

Drupal\Core\Render
View source
interface RenderCacheInterface {
    
    /**
     * Gets a cacheable render array for a render array and its rendered output.
     *
     * Given a render array and its rendered output (HTML string), return an array
     * data structure that allows the render array and its associated metadata to
     * be cached reliably (and is serialization-safe).
     *
     * If Drupal needs additional rendering metadata to be cached at some point,
     * consumers of this method will continue to work. Those who only cache
     * certain parts of a render array will cease to work.
     *
     * @param array $elements
     *   A render array, on which \Drupal\Core\Render\RendererInterface::render()
     *   has already been invoked.
     *
     * @return array
     *   An array representing the cacheable data for this render array.
     */
    public function getCacheableRenderArray(array $elements);
    
    /**
     * Gets the cached, pre-rendered element of a renderable element from cache.
     *
     * @param array $elements
     *   A renderable array.
     *
     * @return array|false
     *   A renderable array, with the original element and all its children pre-
     *   rendered, or FALSE if no cached copy of the element is available.
     *
     * @see \Drupal\Core\Render\RendererInterface::render()
     * @see ::set()
     */
    public function get(array $elements);
    
    /**
     * Caches the rendered output of a renderable array.
     *
     * May be called by an implementation of \Drupal\Core\Render\RendererInterface
     * while rendering, if the #cache property is set.
     *
     * @param array $elements
     *   A renderable array.
     * @param array $pre_bubbling_elements
     *   A renderable array corresponding to the state (in particular, the
     *   cacheability metadata) of $elements prior to the beginning of its
     *   rendering process, and therefore before any bubbling of child
     *   information has taken place. Only the #cache property is used by this
     *   function, so the caller may omit all other properties and children from
     *   this array.
     *
     * @return bool|null
     *   Returns FALSE if no cache item could be created, NULL otherwise.
     *
     * @see ::get()
     */
    public function set(array &$elements, array $pre_bubbling_elements);

}

Members

Title Sort descending Modifiers Object type Summary Overrides
RenderCacheInterface::get public function Gets the cached, pre-rendered element of a renderable element from cache. 1
RenderCacheInterface::getCacheableRenderArray public function Gets a cacheable render array for a render array and its rendered output. 1
RenderCacheInterface::set public function Caches the rendered output of a renderable array. 1

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