From bdec105a72ef6c8d832fd2e80fabf1681a2d0616 Mon Sep 17 00:00:00 2001 From: Philipp Kolesnikov Date: Sun, 26 Jul 2020 15:13:16 +1000 Subject: [PATCH] [Cache] Fix #37667 --- .../Component/Cache/Adapter/ArrayAdapter.php | 4 ++++ .../Tests/Adapter/TagAwareAdapterTest.php | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php b/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php index ff826f47a2..7e97875435 100644 --- a/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/ArrayAdapter.php @@ -113,6 +113,10 @@ class ArrayAdapter implements AdapterInterface, LoggerAwareInterface, Resettable $value = $item["\0*\0value"]; $expiry = $item["\0*\0expiry"]; + if (0 === $expiry) { + $expiry = PHP_INT_MAX; + } + if (null !== $expiry && $expiry <= time()) { $this->deleteItem($key); diff --git a/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php index 0108b9250b..11907a0313 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php @@ -14,6 +14,7 @@ namespace Symfony\Component\Cache\Tests\Adapter; use PHPUnit\Framework\MockObject\MockObject; use Psr\Cache\CacheItemInterface; use Symfony\Component\Cache\Adapter\AdapterInterface; +use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Adapter\TagAwareAdapter; @@ -255,6 +256,25 @@ class TagAwareAdapterTest extends AdapterTestCase $this->assertFalse($anotherPool->hasItem($itemKey)); } + public function testInvalidateTagsWithArrayAdapter() + { + $adapter = new TagAwareAdapter(new ArrayAdapter()); + + $item = $adapter->getItem('foo'); + + $this->assertFalse($item->isHit()); + + $item->tag('bar'); + $item->expiresAfter(100); + $adapter->save($item); + + $this->assertTrue($adapter->getItem('foo')->isHit()); + + $adapter->invalidateTags(['bar']); + + $this->assertFalse($adapter->getItem('foo')->isHit()); + } + public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemAndOnlyHasTags() { $pool = $this->createCachePool();