You are here

function _d8cache_cache_tags_calculate_checksum in Drupal 8 Cache Backport 7

Calculates the current checksum for a given set of tags.

Parameters

array $tags: The array of tags to calculate the checksum for.

Return value

int The calculated checksum.

2 calls to _d8cache_cache_tags_calculate_checksum()
d8cache_cache_tags_get_current_checksum in ./d8cache.module
Returns the sum total of validations for a given set of tags.
d8cache_cache_tags_is_valid in ./d8cache.module
Returns whether the checksum is valid for the given cache tags.

File

./d8cache.module, line 293
Main module file for the D8 caching system backport.

Code

function _d8cache_cache_tags_calculate_checksum(array $tags) {
  $tag_cache =& drupal_static('d8cache_tag_cache', array());
  $checksum = 0;
  $query_tags = array_diff($tags, array_keys($tag_cache));

  // Try to load from cache first.
  if ($query_tags) {
    $tag_cache += _d8cache_cache_tags_load_from_cache($query_tags);
  }

  // Are there any remaining tags to query?
  if ($query_tags) {
    $result = _d8cache_cache_tags_load_from_db($query_tags);
    _d8cache_cache_tags_update_cache($result);
    $tag_cache += $result;
  }
  foreach ($tags as $tag) {
    $checksum += $tag_cache[$tag];
  }
  return $checksum;
}