1
0
mirror of synced 2024-12-05 03:06:05 +03:00

Simplified way to fetch multiple entries when index does not matter

This commit is contained in:
Menno Holtkamp 2015-04-14 09:47:57 +02:00
parent 012f33524b
commit dbc29d28d2

View File

@ -100,30 +100,19 @@ class DefaultRegion implements Region
*/
public function getMultiple(CollectionCacheEntry $collection)
{
$keysToRetrieve = array();
$result = array();
foreach ($collection->identifiers as $index => $key) {
$keysToRetrieve[$index] = $this->name . '_' . $key->hash;
foreach ($collection->identifiers as $key) {
$entry = $this->cache->fetch($this->name . '_' . $key->hash);
if ($entry === false) {
$result = null;
break;
} else {
$result[] = $entry;
}
}
$items = array_filter(
array_map([$this->cache, 'fetch'], $keysToRetrieve),
function ($retrieved) {
return false !== $retrieved;
}
);
if (count($items) !== count($keysToRetrieve)) {
return null;
}
$returnableItems = array();
foreach ($keysToRetrieve as $index => $key) {
$returnableItems[$index] = $items[$index];
}
return $returnableItems;
return $result;
}
/**