final protected function getMultipleCacheItems(
        array $ids,
        string $keyPrefix,
        callable $missingLoader,
        callable $loadedTagger,
        array $keySuffixes = []
    ): array {
        if (empty($ids)) {
            return [];
        }

        // Generate unique cache keys
        $cacheKeys = [];
        $cacheKeysToIdMap = [];
        foreach (\array_unique($ids) as $id) {
            $key = $keyPrefix . $id . ($keySuffixes[$id] ?? '');
            $cacheKeys[] = $key;
            $cacheKeysToIdMap[$key] = $id;
        }

        // Load cache items by cache keys (will contain hits and misses)
        $list = [];
        $cacheMisses = [];
        foreach ($this->cache->getItems($cacheKeys) as $key => $cacheItem) {
            $id = $cacheKeysToIdMap[$key];
            if ($cacheItem->isHit()) {
                $list[$id] = $cacheItem->get();
            } else {
                $cacheMisses[] = $id;
                $list[$id] = $cacheItem;
            }
        }

        // No misses, return completely cached list
        if (empty($cacheMisses)) {
            return $list;
        }

        // Load missing items, save to cache & apply to list if found
        $loadedList = $missingLoader($cacheMisses);
        foreach ($cacheMisses as $id) {
            if (isset($loadedList[$id])) {
                $this->cache->save(
                    $list[$id]
                        ->set($loadedList[$id])
                        ->tag($loadedTagger($loadedList[$id]))
                );
                $list[$id] = $loadedList[$id];
            } else {
                unset($list[$id]);
            }
        }

        return $list;
    }
final protected function getMultipleCacheItems(
        array $ids,
        string $keyPrefix,
        callable $missingLoader,
        callable $loadedTagger,
        array $keySuffixes = []
    ): array {
        if (empty($ids)) {
            return [];
        }

        // Generate unique cache keys
        $cacheKeys = [];
        $cacheKeysToIdMap = [];
        foreach (\array_unique($ids) as $id) {
            $key = $keyPrefix . $id . ($keySuffixes[$id] ?? '');
            $cacheKeys[] = $key;
            $cacheKeysToIdMap[$key] = $id;
        }

        // Load cache items by cache keys (will contain hits and misses)
        $list = [];
        $cacheMisses = [];
        foreach ($this->cache->getItems($cacheKeys) as $key => $cacheItem) {
            $id = $cacheKeysToIdMap[$key];
            if ($cacheItem->isHit()) {
                $list[$id] = $cacheItem->get();
            } else {
                $cacheMisses[] = $id;
                $list[$id] = $cacheItem;
            }
        }

        // No misses, return completely cached list
        if (empty($cacheMisses)) {
            return $list;
        }

        // Load missing items, save to cache & apply to list if found
        $loadedList = $missingLoader($cacheMisses);
        foreach ($cacheMisses as $id) {
            if (isset($loadedList[$id])) {
                $this->cache->save(
                    $list[$id]
                        ->set($loadedList[$id])
                        ->tag($loadedTagger($loadedList[$id]))
                );
                $list[$id] = $loadedList[$id];
            } else {
                unset($list[$id]);
            }
        }

        return $list;
    }
final protected function getMultipleCacheItems ( array $ ids , string $ keyPrefix , callable $ missingLoader , callable $ loadedTagger , array $ keySuffixes = [ ] ) : array { if ( empty ( $ ids ) ) { return [ ] ; } // Generate unique cache keys $ cacheKeys = [ ] ; $ cacheKeysToIdMap = [ ] ; foreach ( \ array_unique ( $ ids ) as $ id ) { $ key = $ keyPrefix . $ id . ( $ keySuffixes [ $ id ] ?? '' ) ; $ cacheKeys [ ] = $ key ; $ cacheKeysToIdMap [ $ key ] = $ id ; } // Load cache items by cache keys (will contain hits and misses) $ list = [ ] ; $ cacheMisses = [ ] ; foreach ( $ this -> cache -> getItems ( $ cacheKeys ) as $ key => $ cacheItem ) { $ id = $ cacheKeysToIdMap [ $ key ] ; if ( $ cacheItem -> isHit ( ) ) { $ list [ $ id ] = $ cacheItem -> get ( ) ; } else { $ cacheMisses [ ] = $ id ; $ list [ $ id ] = $ cacheItem ; } } // No misses, return completely cached list if ( empty ( $ cacheMisses ) ) { return $ list ; } // Load missing items, save to cache & apply to list if found $ loadedList = $ missingLoader ( $ cacheMisses ) ; foreach ( $ cacheMisses as $ id ) { if ( isset ( $ loadedList [ $ id ] ) ) { $ this -> cache -> save ( $ list [ $ id ] -> set ( $ loadedList [ $ id ] ) -> tag ( $ loadedTagger ( $ loadedList [ $ id ] ) ) ) ; $ list [ $ id ] = $ loadedList [ $ id ] ; } else { unset ( $ list [ $ id ] ) ; } } return $ list ; }
Helper for getting multiple cache items in one call and do the id extraction for you.

Cache items must be stored with a key in the following format "${keyPrefix}${id}", like "ez-content-info-${id}",
in order for this method to be able to prefix key on id's and also extract key prefix afterwards.

It also optionally supports a key suffixs, for use on a variable argument that affects all lookups,
like translations, i.e. "ez-content-${id}-${translationKey}" where $keySuffixes = [$id => "-${translationKey}"].

@param array $ids
@param string $keyPrefix E.g "ez-content-"
@param callable $missingLoader Function for loading missing objects, gets array with missing id's as argument,
expects return value to be array with id as key. Missing items should be missing.
@param callable $loadedTagger Function for tagging loaded object, gets object as argument, return array of tags.
@param array $keySuffixes Optional, key is id as provided in $ids, and value is a key suffix e.g. "-eng-Gb"

@return array
Helper for getting multiple cache items in one call and do the id extraction for you .