Skip to content

[13.x] Fix memoized tagged cache many() returning null for numeric keys - #61780

Merged
taylorotwell merged 1 commit into
laravel:13.xfrom
sajjadhossainshohag:fix-memoized-tagged-cache-numeric-keys
Sep 29, 2026
Merged

taylorotwell merged 1 commit into
laravel:13.xfrom
sajjadhossainshohag:fix-memoized-tagged-cache-numeric-keys

Conversation

@sajjadhossainshohag

Copy link
Copy Markdown
Contributor

Cache::memo()->tags()->many() returns null for cached values when the keys are integers, such as model ids:

Cache::tags(['users'])->put(10, 'Taylor', 60);
Cache::tags(['users'])->put(20, 'Tim', 60);

Cache::tags(['users'])->many([10, 20]);         // [10 => 'Taylor', 20 => 'Tim']
Cache::memo()->tags(['users'])->many([10, 20]); // [10 => null, 20 => null]

The same happens through get([...]) and getMultiple(), and when some of the keys were already memoized.

MemoizedTaggedCache::many() combines the memoized values with the ones it just retrieved using array_merge(), which renumbers integer keys. 10 and 20 become 0 and 1, so the array_key_exists() lookup that builds the result misses and falls back to the default.

This is the same bug that #57862 fixed for the untagged MemoizedStore, and the tagged memoized cache from #61593 brought it back. This PR uses += instead, which keeps the keys. The two arrays never share a key, because only missing keys are retrieved.

The tests cover a fresh retrieval, a second memoized retrieval, and a partially memoized one.

@taylorotwell
taylorotwell merged commit 4d6522d into laravel:13.x Sep 29, 2026
123 checks passed
@sajjadhossainshohag
sajjadhossainshohag deleted the fix-memoized-tagged-cache-numeric-keys branch September 29, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants