function LruMemoryCache::handleCacheHits

Moves an array of cache items to the most recently used positions.

Parameters

array $items: An array of cache items keyed by cid.

2 calls to LruMemoryCache::handleCacheHits()
LruMemoryCache::get in core/lib/Drupal/Core/Cache/MemoryCache/LruMemoryCache.php
Returns data from the persistent cache.
LruMemoryCache::getMultiple in core/lib/Drupal/Core/Cache/MemoryCache/LruMemoryCache.php
Returns data from the persistent cache when given an array of cache IDs.

File

core/lib/Drupal/Core/Cache/MemoryCache/LruMemoryCache.php, line 59

Class

LruMemoryCache
Defines a least recently used (LRU) static cache implementation.

Namespace

Drupal\Core\Cache\MemoryCache

Code

private function handleCacheHits(array $items) : void {
    $last_key = array_key_last($this->cache);
    foreach ($items as $cid => $cached) {
        if ($cached->valid && $cid !== $last_key) {
            // Move valid items to the end of the array, so they will be removed
            // last.
            unset($this->cache[$cid]);
            $this->cache[$cid] = $cached;
            $last_key = $cid;
        }
    }
}

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