bug #37671 [Cache] fix saving no-expiry items with ArrayAdapter (philipp-kolesnikov)
This PR was merged into the 3.4 branch.
Discussion
----------
[Cache] fix saving no-expiry items with ArrayAdapter
| Q | A
| ------------- | ---
| Branch? | 3.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix #37667
| License | MIT
| Doc PR |
0 is a special value that means "infinity".
Commits
-------
bdec105a72
[Cache] Fix #37667
This commit is contained in:
commit
b61fa4480b
@ -113,6 +113,10 @@ class ArrayAdapter implements AdapterInterface, LoggerAwareInterface, Resettable
|
|||||||
$value = $item["\0*\0value"];
|
$value = $item["\0*\0value"];
|
||||||
$expiry = $item["\0*\0expiry"];
|
$expiry = $item["\0*\0expiry"];
|
||||||
|
|
||||||
|
if (0 === $expiry) {
|
||||||
|
$expiry = PHP_INT_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
if (null !== $expiry && $expiry <= time()) {
|
if (null !== $expiry && $expiry <= time()) {
|
||||||
$this->deleteItem($key);
|
$this->deleteItem($key);
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ namespace Symfony\Component\Cache\Tests\Adapter;
|
|||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use Psr\Cache\CacheItemInterface;
|
use Psr\Cache\CacheItemInterface;
|
||||||
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
use Symfony\Component\Cache\Adapter\AdapterInterface;
|
||||||
|
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||||
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
|
||||||
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
|
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
|
||||||
|
|
||||||
@ -255,6 +256,25 @@ class TagAwareAdapterTest extends AdapterTestCase
|
|||||||
$this->assertFalse($anotherPool->hasItem($itemKey));
|
$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()
|
public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemAndOnlyHasTags()
|
||||||
{
|
{
|
||||||
$pool = $this->createCachePool();
|
$pool = $this->createCachePool();
|
||||||
|
Reference in New Issue
Block a user