From 3f30b25ae1abfe33d76378285e64c1b2cc018111 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 23 Oct 2024 10:45:17 +0200 Subject: [PATCH] ignore metadata in values returned by the PSR16 cache --- src/Symfony/Component/Cache/Psr16Cache.php | 12 +----------- .../Component/Cache/Tests/Psr16CacheTest.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Component/Cache/Psr16Cache.php b/src/Symfony/Component/Cache/Psr16Cache.php index f21384fee967f..bdf9e056e5fba 100644 --- a/src/Symfony/Component/Cache/Psr16Cache.php +++ b/src/Symfony/Component/Cache/Psr16Cache.php @@ -30,7 +30,6 @@ class Psr16Cache implements CacheInterface, PruneableInterface, ResettableInterf private ?\Closure $createCacheItem = null; private ?CacheItem $cacheItemPrototype = null; - private static \Closure $packCacheItem; public function __construct(CacheItemPoolInterface $pool) { @@ -66,15 +65,6 @@ static function ($key, $value, $allowInt = false) use (&$cacheItemPrototype) { return $createCacheItem($key, null, $allowInt)->set($value); }; - self::$packCacheItem ??= \Closure::bind( - static function (CacheItem $item) { - $item->newMetadata = $item->metadata; - - return $item->pack(); - }, - null, - CacheItem::class - ); } public function get($key, $default = null): mixed @@ -156,7 +146,7 @@ public function getMultiple($keys, $default = null): iterable } foreach ($items as $key => $item) { - $values[$key] = $item->isHit() ? (self::$packCacheItem)($item) : $default; + $values[$key] = $item->isHit() ? $item->get() : $default; } return $values; diff --git a/src/Symfony/Component/Cache/Tests/Psr16CacheTest.php b/src/Symfony/Component/Cache/Tests/Psr16CacheTest.php index 264679aecc1b6..07472c646e525 100644 --- a/src/Symfony/Component/Cache/Tests/Psr16CacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Psr16CacheTest.php @@ -14,6 +14,7 @@ use Cache\IntegrationTests\SimpleCacheTest; use Psr\SimpleCache\CacheInterface; use Symfony\Component\Cache\Adapter\FilesystemAdapter; +use Symfony\Component\Cache\Adapter\TagAwareAdapter; use Symfony\Component\Cache\PruneableInterface; use Symfony\Component\Cache\Psr16Cache; @@ -172,6 +173,22 @@ protected function isPruned(CacheInterface $cache, string $name): bool return !file_exists($getFileMethod->invoke($pool, $name)); } + + public function testGetMultipleWithTagAwareAdapter() + { + if (isset($this->skippedTests[__FUNCTION__])) { + $this->markTestSkipped($this->skippedTests[__FUNCTION__]); + } + + $cache = new Psr16Cache(new TagAwareAdapter(new FilesystemAdapter())); + + $cache->set('foo', 'foo-val'); + $cache->set('bar', 'bar-val'); + $cache->set('baz', 'baz-val'); + $cache->set('qux', 'qux-val'); + + $this->assertEquals(['foo' => 'foo-val', 'bar' => 'bar-val', 'baz' => 'baz-val', 'qux' => 'qux-val'], $cache->getMultiple(['foo', 'bar', 'baz', 'qux'])); + } } class NotUnserializable