You are here

function _render_cache_pre_render in Render cache 7

2 calls to _render_cache_pre_render()
render_cache_entity_view_callback in ./render_cache.module
Override entity API rendering callback to add a caching layer.
render_cache_view_field in ./render_cache.module
Helper function to view a single entity field.

File

./render_cache.module, line 153
Hook implementations and frequently used functions for render cache module.

Code

function _render_cache_pre_render(array &$render, $cid, $cache_info) {
  if (isset($cache_info['granularity']) && $cache_info['granularity'] != DRUPAL_NO_CACHE) {
    if (empty($cache_info['render_cache_render_to_markup'])) {
      cache_set($cid, $render, 'cache_render');
    }
    else {

      // Process markup with drupal_render() caching.
      $render['#cache'] = $cache_info;

      // Explicitly set cache id.
      $render['#cache']['cid'] = $cid;
      $render_cache_attached = array();

      // Preserve some properties in #attached?
      if (!empty($cache_info['render_cache_render_to_markup']['preserve properties']) && is_array($cache_info['render_cache_render_to_markup']['preserve properties'])) {
        foreach ($cache_info['render_cache_render_to_markup']['preserve properties'] as $key) {
          if (isset($render[$key])) {
            $render_cache_attached[$key] = $render[$key];
          }
        }
      }
      if (!empty($render_cache_attached)) {
        $render['#attached']['render_cache'] = $render_cache_attached;
      }

      // Do we want to render now?
      if (empty($cache_info['render_cache_render_to_markup']['cache late'])) {

        // And save things. Also add our preserved properties back.
        $render = array(
          '#markup' => drupal_render($render),
        ) + $render_cache_attached;
      }
    }
  }
  return $render;
}