You are here

public function BackendChain::get in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Cache/BackendChain.php \Drupal\Core\Cache\BackendChain::get()
  2. 9 core/lib/Drupal/Core/Cache/BackendChain.php \Drupal\Core\Cache\BackendChain::get()

File

core/lib/Drupal/Core/Cache/BackendChain.php, line 65

Class

BackendChain
Defines a chained cache implementation for combining multiple cache backends.

Namespace

Drupal\Core\Cache

Code

public function get($cid, $allow_invalid = FALSE) {
  foreach ($this->backends as $index => $backend) {
    if (($return = $backend
      ->get($cid, $allow_invalid)) !== FALSE) {

      // We found a result, propagate it to all missed backends.
      if ($index > 0) {
        for ($i = $index - 1; 0 <= $i; --$i) {
          $this->backends[$i]
            ->set($cid, $return->data, $return->expire, $return->tags);
        }
      }
      return $return;
    }
  }
  return FALSE;
}