function render_cache_get_entity_cid in Render cache 7
Retrieve cache ID to use for entity render caching.
Parameters
object $entity: The entity object being rendered.
array $cache_info: A drupal_render style cache array().
array $context: The context of the entity, with the following keys:
- entity_type
- entity_id
- entity_revision_id
- bundle
- langcode
- view_mode
If a field is being rendered, the following additional keys are required:
- field_name
- deltas
- display
Return value
string
2 calls to render_cache_get_entity_cid()
- 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 293 - Hook implementations and frequently used functions for render cache module.
Code
function render_cache_get_entity_cid($entity, &$cache_info, $context) {
if (isset($cache_info['cid'])) {
return $cache_info['cid'];
}
$cache_info += render_cache_cache_info_defaults();
/* @see hook_render_cache_entity_cache_info_alter() */
drupal_alter('render_cache_entity_cache_info', $cache_info, $entity, $context);
$cid_parts = array();
$hash = array();
if (!empty($cache_info['keys']) && is_array($cache_info['keys'])) {
$cid_parts = $cache_info['keys'];
}
// Add drupal_render cid_parts based on granularity
$granularity = isset($cache_info['granularity']) ? $cache_info['granularity'] : NULL;
$cid_parts = array_merge($cid_parts, drupal_render_cid_parts($granularity));
// Calculate hash to expire cached items automatically.
$hash['id'] = !empty($context['entity_revision_id']) ? $context['entity_revision_id'] : $context['entity_id'];
$hash['bundle'] = !empty($context['bundle']) ? $context['bundle'] : $context['entity_type'];
$hash['langcode'] = !empty($context['langcode']) ? $context['langcode'] : $GLOBALS['language_content']->language;
$hash['modified'] = entity_modified_last($context['entity_type'], $entity);
$hash['render_method'] = !empty($cache_info['render_cache_render_to_markup']);
if ($hash['render_method']) {
$hash['render_options'] = serialize($cache_info['render_cache_render_to_markup']);
}
if (!empty($context['field_name'])) {
$hash['deltas'] = implode(',', $context['deltas']);
$hash['display'] = serialize(array_intersect_key($context['display'], array(
'type' => '',
'settings' => '',
)));
}
else {
// Generally hash per view_mode - its unlikely they are the same.
$hash['view_mode'] = !empty($context['view_mode']) ? $context['view_mode'] : 'default';
}
// Allow modules to modify $hash for custom invalidating.
/* @see hook_render_cache_entity_hash_alter() */
drupal_alter('render_cache_entity_hash', $hash, $entity, $cache_info, $context);
$cid_parts[] = sha1(implode('-', $hash));
/* @see hook_render_cache_entity_cid_alter() */
drupal_alter('render_cache_entity_cid', $cid_parts, $entity, $cache_info, $context);
return implode(':', $cid_parts);
}