You are here

function d8cache_invalidate_cache_tags in Drupal 8 Cache Backport 7

Implements hook_invalidate_cache_tags().

File

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

Code

function d8cache_invalidate_cache_tags($tags) {

  // Not using drupal_static because the detection is based on the running
  // code, and that is not going to change during execution.
  static $use_transaction_callback;
  $deferred_tags =& drupal_static('d8cache_deferred_tags', array());
  $connection = Database::getConnection();
  if (!isset($use_transaction_callback)) {
    $use_transaction_callback = _d8cache_has_transaction_callbacks($connection);
  }
  if (!$use_transaction_callback) {

    // Core support missing, use the old (deadlock-prone) invalidation code.
    return d8cache_OLD_invalidate_cache_tags($tags);
  }
  if ($connection
    ->inTransaction()) {

    // We are inside a transaction, we must defer until the end of the transaction.
    foreach ($tags as $tag) {
      if (empty($deferred_tags)) {
        $connection
          ->addRootTransactionEndCallback('d8cache_root_transaction_end');
      }
      $deferred_tags[$tag] = TRUE;
    }
  }
  else {

    // Not in a transction, directly invalidate instead.
    d8cache_do_invalidate_cache_tags($tags);
  }
}