function VariationCache::getValidatedCachedRedirectChain
Same name and namespace in other branches
- main core/lib/Drupal/Core/Cache/VariationCache.php \Drupal\Core\Cache\VariationCache::getValidatedCachedRedirectChain()
Retrieved the redirect chain from cache, validating each part.
Parameters
string[] $keys: The cache keys to retrieve the redirect chain for.
\Drupal\Core\Cache\CacheableDependencyInterface $initial_cacheability: The initial cacheability for the redirect chain.
Return value
array The part of the cached redirect chain, if any, that is still valid.
2 calls to VariationCache::getValidatedCachedRedirectChain()
- VariationCache::getMultiple in core/
lib/ Drupal/ Core/ Cache/ VariationCache.php - Gets multiple cache entries based on a set of cache keys.
- VariationCache::getRedirectChain in core/
lib/ Drupal/ Core/ Cache/ VariationCache.php - Performs a full get, returning every step of the way.
File
-
core/
lib/ Drupal/ Core/ Cache/ VariationCache.php, line 375
Class
- VariationCache
- Wraps a regular cache backend to make it support cache contexts.
Namespace
Drupal\Core\CacheCode
protected function getValidatedCachedRedirectChain(array $keys, CacheableDependencyInterface $initial_cacheability) : array {
$cid = $this->createCacheIdFast($keys, $initial_cacheability);
if (!isset($this->redirectChainCache[$cid])) {
return [];
}
$chain = $this->redirectChainCache[$cid];
// Only use that part of the redirect chain that is still valid. Even though
// we do not store cache hits in the internal redirect chain cache, we can
// still reuse the whole chain up until what would have been a cache hit.
//
// If part of a redirect chain no longer matches because cache contexts
// changed values, we could perhaps still reuse part of the chain until we
// encounter a redirect for the changed cache context value.
//
// There is one special case: If the very last item of the chain is a cache
// redirect, and we cannot find anything for it, we still add the redirect
// to the validated chain because the only way a cached chain ends in a
// redirect is if it led to a cache hit in ::getRedirectChain().
$valid_parts = [];
$last_key = array_key_last($chain);
foreach ($chain as $key => $result) {
if ($result && $result->data instanceof CacheRedirect) {
$cid = $this->createCacheIdFast($keys, $result->data);
if (!isset($chain[$cid]) && $last_key !== $key) {
break;
}
}
$valid_parts[$key] = $result;
}
return $valid_parts;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.