function VariationCache::getRedirectChain

Same name and namespace in other branches
  1. 10 core/lib/Drupal/Core/Cache/VariationCache.php \Drupal\Core\Cache\VariationCache::getRedirectChain()

Performs a full get, returning every step of the way.

This will check whether there is a cache redirect and follow it if so. It will keep following redirects until it gets to a cache miss or the actual cache object.

Parameters

string[] $keys: The cache keys to retrieve the cache entry for.

\Drupal\Core\Cache\CacheableDependencyInterface $initial_cacheability: The cache metadata of the data to store before other systems had a chance to adjust it. This is also commonly known as "pre-bubbling" cacheability.

Return value

array Every cache get that lead to the final result, keyed by the cache ID used to query the cache for that result.

4 calls to VariationCache::getRedirectChain()
VariationCache::delete in core/lib/Drupal/Core/Cache/VariationCache.php
Deletes an item from the cache.
VariationCache::get in core/lib/Drupal/Core/Cache/VariationCache.php
Gets a cache entry based on cache keys.
VariationCache::invalidate in core/lib/Drupal/Core/Cache/VariationCache.php
Marks a cache item as invalid.
VariationCache::set in core/lib/Drupal/Core/Cache/VariationCache.php
Stores data in the cache.

File

core/lib/Drupal/Core/Cache/VariationCache.php, line 331

Class

VariationCache
Wraps a regular cache backend to make it support cache contexts.

Namespace

Drupal\Core\Cache

Code

protected function getRedirectChain(array $keys, CacheableDependencyInterface $initial_cacheability) : array {
  $chain = $this->getValidatedCachedRedirectChain($keys, $initial_cacheability);
  // Initiate the chain if we couldn't retrieve (a partial) one from memory.
  if (empty($chain)) {
    $cid = $initial_cid = $this->createCacheIdFast($keys, $initial_cacheability);
    $chain[$cid] = $result = $this->cacheBackend
      ->get($cid);
  }
  else {
    $initial_cid = array_key_first($chain);
    $result = end($chain);
  }
  while ($result && $result->data instanceof CacheRedirect) {
    $cid = $this->createCacheIdFast($keys, $result->data);
    $chain[$cid] = $result = $this->cacheBackend
      ->get($cid);
  }
  // When storing the redirect chain in memory we must take care to not store
  // a cache hit as they can be invalidated, unlike CacheRedirect objects. We
  // do store the rest of the chain because redirects can be reused safely.
  $chain_to_cache = $chain;
  if ($result !== FALSE) {
    array_pop($chain_to_cache);
  }
  $this->redirectChainCache[$initial_cid] = $chain_to_cache;
  return $chain;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.