Skip to content

Commit 2849cd6

Browse files
authored
[12.x] Incorrect result of MemoizedStore::many with numeric keys and empty prefix (#57862)
* [12.x] MemoizedStoreTest with empty prefix * [12.x] MemoizedStore fix with empty prefix and numeric keys
1 parent 976d0a8 commit 2849cd6

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/Illuminate/Cache/MemoizedStore.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,9 @@ public function many(array $keys)
6868

6969
if (count($missing) > 0) {
7070
$retrieved = tap($this->repository->many($missing), function ($values) {
71-
$this->cache = [
72-
...$this->cache,
73-
...collect($values)->mapWithKeys(fn ($value, $key) => [
74-
$this->prefix($key) => $value,
75-
]),
76-
];
71+
foreach ($values as $key => $value) {
72+
$this->cache[$this->prefix($key)] = $value;
73+
}
7774
});
7875
}
7976

tests/Integration/Cache/MemoizedStoreTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,21 @@ public function test_it_uses_correct_keys_for_getMultiple()
121121
$this->assertSame($cacheValue, $memoValue);
122122
}
123123

124+
public function test_it_uses_correct_keys_for_getMultiple_with_empty_prefix()
125+
{
126+
Cache::setPrefix(null);
127+
128+
$data = [
129+
'1' => 'one',
130+
0 => 'zero',
131+
];
132+
Cache::putMany($data);
133+
134+
$this->assertSame($data, Cache::memo()->many(array_keys($data)));
135+
// ensure correct on the second memoized retrieval
136+
$this->assertSame($data, Cache::memo()->many(array_keys($data)));
137+
}
138+
124139
public function test_null_values_are_memoized_when_retrieving_multiple_values()
125140
{
126141
$live = Cache::getMultiple(['name.0', 'name.1']);

0 commit comments

Comments
 (0)