function drupal_render_cache_set

Caches the rendered output of a renderable element.

This is called by drupal_render() if the #cache property is set on an element.

Parameters

$markup: The rendered output string of $elements.

$elements: A renderable array.

See also

drupal_render_cache_get()

1 call to drupal_render_cache_set()
drupal_render in drupal/core/includes/common.inc
Renders HTML given a structured array tree.

File

drupal/core/includes/common.inc, line 5668
Common functions that many Drupal modules will need to reference.

Code

function drupal_render_cache_set(&$markup, $elements) {

  // Create the cache ID for the element.
  if (!in_array($_SERVER['REQUEST_METHOD'], array(
    'GET',
    'HEAD',
  )) || !($cid = drupal_render_cid_create($elements))) {
    return FALSE;
  }

  // Cache implementations are allowed to modify the markup, to support
  // replacing markup with edge-side include commands. The supporting cache
  // backend will store the markup in some other key (like
  // $data['#real-value']) and return an include command instead. When the
  // ESI command is executed by the content accelerator, the real value can
  // be retrieved and used.
  $data['#markup'] =& $markup;

  // Persist attached data associated with this element.
  $attached = drupal_render_collect_attached($elements, TRUE);
  if ($attached) {
    $data['#attached'] = $attached;
  }
  $bin = isset($elements['#cache']['bin']) ? $elements['#cache']['bin'] : 'cache';
  $expire = isset($elements['#cache']['expire']) ? $elements['#cache']['expire'] : CacheBackendInterface::CACHE_PERMANENT;
  $tags = isset($elements['#cache']['tags']) ? $elements['#cache']['tags'] : array();
  cache($bin)
    ->set($cid, $data, $expire, $tags);
}