From d3af877022d464bb18e9c3493cec2ab351f24414 Mon Sep 17 00:00:00 2001 From: David Maicher Date: Fri, 4 Sep 2020 20:10:14 +0200 Subject: [PATCH] [Cache] fix ProxyAdapter not persisting items with infinite expiration --- .../Component/Cache/Adapter/ProxyAdapter.php | 2 +- ...TagAwareAndProxyAdapterIntegrationTest.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php b/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php index a03c582d8c..b126b5a7c8 100644 --- a/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ProxyAdapter.php @@ -88,7 +88,7 @@ class ProxyAdapter implements AdapterInterface, CacheInterface, PruneableInterfa $item["\0*\0value"] = ["\x9D".pack('VN', (int) (0.1 + $metadata[self::METADATA_EXPIRY] - self::METADATA_EXPIRY_OFFSET), $metadata[self::METADATA_CTIME])."\x5F" => $item["\0*\0value"]]; } $innerItem->set($item["\0*\0value"]); - $innerItem->expiresAt(null !== $item["\0*\0expiry"] ? \DateTime::createFromFormat('U.u', sprintf('%.6f', $item["\0*\0expiry"])) : null); + $innerItem->expiresAt(null !== $item["\0*\0expiry"] ? \DateTime::createFromFormat('U.u', sprintf('%.6f', 0 === $item["\0*\0expiry"] ? \PHP_INT_MAX : $item["\0*\0expiry"])) : null); }, null, CacheItem::class diff --git a/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAndProxyAdapterIntegrationTest.php b/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAndProxyAdapterIntegrationTest.php index e53b407028..4f30fdddd1 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAndProxyAdapterIntegrationTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAndProxyAdapterIntegrationTest.php @@ -24,6 +24,29 @@ class TagAwareAndProxyAdapterIntegrationTest extends TestCase $cache->save($item); $this->assertSame('bar', $cache->getItem('foo')->get()); + + $cache->invalidateTags(['tag2']); + + $this->assertFalse($cache->getItem('foo')->isHit()); + } + + public function testIntegrationUsingProxiedAdapterForTagsPool() + { + $arrayAdapter = new ArrayAdapter(); + $cache = new TagAwareAdapter($arrayAdapter, new ProxyAdapter($arrayAdapter)); + + $item = $cache->getItem('foo'); + $item->expiresAfter(600); + $item->tag(['baz']); + $item->set('bar'); + $cache->save($item); + + $this->assertSame('bar', $cache->getItem('foo')->get()); + $this->assertTrue($cache->getItem('foo')->isHit()); + + $cache->invalidateTags(['baz']); + + $this->assertFalse($cache->getItem('foo')->isHit()); } public function dataProvider(): array