You are here

protected function BaseController::getCacheIdInfo in Render cache 7.2

Provides the fully pouplated cache information for a specific object.

Parameters

object $object:

array $cache_info:

array $context:

Return value

array

Overrides AbstractBaseController::getCacheIdInfo

1 call to BaseController::getCacheIdInfo()
BaseController::getCacheInfoMap in src/RenderCache/Controller/BaseController.php
Returns the cache information map for the given objects.

File

src/RenderCache/Controller/BaseController.php, line 299
Contains \Drupal\render_cache\RenderCache\Controller\BaseController

Class

BaseController
Base class for Controller plugin objects.

Namespace

Drupal\render_cache\RenderCache\Controller

Code

protected function getCacheIdInfo($object, array $cache_info = array(), array $context = array()) {
  $context = $this
    ->getCacheContext($object, $context);
  $cache_info = drupal_array_merge_deep($cache_info, $this
    ->getCacheInfo($object, $context));

  // Ensure these properties are always set.
  $cache_info += array(
    'keys' => array(),
    'hash' => array(),
    'tags' => array(),
    'validate' => array(),
  );

  // Set cache information properties.
  $cache_info['keys'] = array_merge($cache_info['keys'], $this
    ->getCacheKeys($object, $context));
  $cache_info['hash'] = array_merge($cache_info['hash'], $this
    ->getCacheHash($object, $context));
  $cache_info['tags'] = Cache::mergeTags($cache_info['tags'], $this
    ->getCacheTags($object, $context));
  $cache_info['validate'] = drupal_array_merge_deep($cache_info['validate'], $this
    ->getCacheValidate($object, $context));

  // @todo Remove this later.
  $cache_info['hash']['render_method'] = !empty($cache_info['render_cache_render_to_markup']);
  if ($cache_info['hash']['render_method']) {
    $cache_info['hash']['render_options'] = serialize($cache_info['render_cache_render_to_markup']);
  }
  $this
    ->alter('cache_info', $cache_info, $object, $context);

  // If we can't cache this, return with cid set to NULL.
  if ($cache_info['granularity'] == DRUPAL_NO_CACHE) {
    $cache_info['cid'] = NULL;
    return $cache_info;
  }

  // If a Cache ID isset, we need to skip the rest.
  if (isset($cache_info['cid'])) {
    return $cache_info;
  }
  $keys =& $cache_info['keys'];
  $hash =& $cache_info['hash'];
  $tags =& $cache_info['tags'];
  $validate =& $cache_info['validate'];

  // Allow modules to alter the keys, hash, tags and validate.
  $this
    ->alter('keys', $keys, $object, $cache_info, $context);
  $this
    ->alter('hash', $hash, $object, $cache_info, $context);
  $this
    ->alter('tags', $tags, $object, $cache_info, $context);
  $this
    ->alter('validate', $validate, $object, $cache_info, $context);

  // Add drupal_render cid_parts based on granularity.
  $granularity = isset($cache_info['granularity']) ? $cache_info['granularity'] : NULL;
  $cid_parts = array_merge($cache_info['keys'], drupal_render_cid_parts($granularity));

  // Calculate the hash.
  $algorithm = variable_get('render_cache_hash_algorithm', 'md5');
  $cid_parts[] = hash($algorithm, implode('-', $cache_info['hash']));

  // Allow modules to alter the final cid_parts array.
  $this
    ->alter('cid', $cid_parts, $cache_info, $object, $context);
  $cache_info['cid'] = implode(':', $cid_parts);

  // Save the placeholder ID and remove cache id.
  if (!empty($cache_info['render_strategy'])) {
    $cache_info['placeholder_id'] = $cache_info['cid'];
    $cache_info['cid'] = NULL;
  }

  // If the caller caches this customly, unset cid.
  if ($cache_info['granularity'] == DRUPAL_CACHE_CUSTOM) {
    $cache_info['cid'] = NULL;
  }

  // Convert to the new format. (BC layer)
  if (empty($cache_info['render_cache_cache_strategy'])) {
    $strategy = $this
      ->determineCachingStrategy($cache_info);
    $cache_info['render_cache_cache_strategy'] = $strategy;
  }
  if (!empty($cache_info['render_cache_render_to_markup']['preserve properties'])) {
    $cache_info['render_cache_preserve_properties'] = $cache_info['render_cache_render_to_markup']['preserve properties'];
  }
  unset($cache_info['render_cache_render_to_markup']);
  return $cache_info;
}