RenderCacheInterface.php 2.34 KB
Newer Older
1 2 3 4 5 6 7
<?php

namespace Drupal\Core\Render;

/**
 * Defines an interface for caching rendered render arrays.
 *
8
 * @internal
9
 *
10
 * @see sec_caching
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
 * @see \Drupal\Core\Render\RendererInterface
 */
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.
   *
41
   * @return array|false
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
   *   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
67
   *   Returns FALSE if no cache item could be created, NULL otherwise.
68 69 70 71 72 73
   *
   * @see ::get()
   */
  public function set(array &$elements, array $pre_bubbling_elements);

}