From 9372d95a0be9783309c2a74b6b8a190763dfd0ba Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 7 Feb 2024 18:37:43 +0100 Subject: [PATCH] [Cache] Fix BC layer with pre-6.1 cache items --- .../Cache/Adapter/TagAwareAdapter.php | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php b/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php index b7934061ca532..e6b1ac8491585 100644 --- a/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php @@ -146,8 +146,6 @@ public function getItems(array $keys = []): iterable foreach ($keys as $key) { if ('' !== $key && \is_string($key)) { $commit = $commit || isset($this->deferred[$key]); - $key = static::TAGS_PREFIX.$key; - $tagKeys[$key] = $key; // BC with pools populated before v6.1 } } @@ -156,7 +154,7 @@ public function getItems(array $keys = []): iterable } try { - $items = $this->pool->getItems($tagKeys + $keys); + $items = $this->pool->getItems($keys); } catch (InvalidArgumentException $e) { $this->pool->getItems($keys); // Should throw an exception @@ -166,18 +164,24 @@ public function getItems(array $keys = []): iterable $bufferedItems = $itemTags = []; foreach ($items as $key => $item) { - if (isset($tagKeys[$key])) { // BC with pools populated before v6.1 - if ($item->isHit()) { - $itemTags[substr($key, \strlen(static::TAGS_PREFIX))] = $item->get() ?: []; - } - continue; - } - if (null !== $tags = $item->getMetadata()[CacheItem::METADATA_TAGS] ?? null) { $itemTags[$key] = $tags; } $bufferedItems[$key] = $item; + + if (null === $tags) { + $key = static::TAGS_PREFIX.$key; + $tagKeys[$key] = $key; // BC with pools populated before v6.1 + } + } + + if ($tagKeys) { + foreach ($this->pool->getItems($tagKeys) as $key => $item) { + if ($item->isHit()) { + $itemTags[substr($key, \strlen(static::TAGS_PREFIX))] = $item->get() ?: []; + } + } } $tagVersions = $this->getTagVersions($itemTags, false);