diff --git a/src/Illuminate/Cache/MemoizedStore.php b/src/Illuminate/Cache/MemoizedStore.php index 6c24e33346ce..e864e1ec2c86 100644 --- a/src/Illuminate/Cache/MemoizedStore.php +++ b/src/Illuminate/Cache/MemoizedStore.php @@ -68,12 +68,9 @@ public function many(array $keys) if (count($missing) > 0) { $retrieved = tap($this->repository->many($missing), function ($values) { - $this->cache = [ - ...$this->cache, - ...collect($values)->mapWithKeys(fn ($value, $key) => [ - $this->prefix($key) => $value, - ]), - ]; + foreach ($values as $key => $value) { + $this->cache[$this->prefix($key)] = $value; + } }); } diff --git a/tests/Integration/Cache/MemoizedStoreTest.php b/tests/Integration/Cache/MemoizedStoreTest.php index 74022ea8527d..1adc87283573 100644 --- a/tests/Integration/Cache/MemoizedStoreTest.php +++ b/tests/Integration/Cache/MemoizedStoreTest.php @@ -121,6 +121,21 @@ public function test_it_uses_correct_keys_for_getMultiple() $this->assertSame($cacheValue, $memoValue); } + public function test_it_uses_correct_keys_for_getMultiple_with_empty_prefix() + { + Cache::setPrefix(null); + + $data = [ + '1' => 'one', + 0 => 'zero', + ]; + Cache::putMany($data); + + $this->assertSame($data, Cache::memo()->many(array_keys($data))); + // ensure correct on the second memoized retrieval + $this->assertSame($data, Cache::memo()->many(array_keys($data))); + } + public function test_null_values_are_memoized_when_retrieving_multiple_values() { $live = Cache::getMultiple(['name.0', 'name.1']);