Skip to content

Commit

Permalink
Improve CacheTrait::getMultiple()
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed May 31, 2017
1 parent 512aae3 commit c4fac41
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions system/src/Grav/Framework/Cache/CacheTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,17 @@ public function getMultiple($keys, $default = null)

$list = $this->doGetMultiple($keys, $this->miss);

if (count($list) !== count($keys)) {
foreach ($keys as $key) {
if (!array_key_exists($key, $list) || $list[$key] === $this->miss) {
$list[$key] = $default;
}
// Make sure that values are returned in the same order as the keys were given.
$values = [];
foreach ($keys as $key) {
if (!array_key_exists($key, $list) || $list[$key] === $this->miss) {
$values[$key] = $default;
} else {
$values[$key] = $list[$key];
}
}

// Make sure that results are returned in the same order as the keys were given.
return array_replace(array_flip($keys), $list);
return $values;
}

/**
Expand Down

0 comments on commit c4fac41

Please sign in to comment.