This commit is contained in:
Philipp Kolesnikov 2020-07-26 15:13:16 +10:00
parent 81fadc9cc1
commit bdec105a72
2 changed files with 24 additions and 0 deletions

View File

@ -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);

View File

@ -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();