8000 bug #37671 [Cache] fix saving no-expiry items with ArrayAdapter (phil… · symfony/symfony@b61fa44 · GitHub
[go: up one dir, main page]

Skip to content

Commit b61fa44

Browse files
committed
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 ------- bdec105 [Cache] Fix #37667
2 parents b940b5a + bdec105 commit b61fa44

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Symfony/Component/Cache/Adapter/ArrayAdapter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ public function save(CacheItemInterface $item)
113113
$value = $item["\0*\0value"];
114114
$expiry = $item["\0*\0expiry"];
115115

116+
if (0 === $expiry) {
117+
$expiry = PHP_INT_MAX;
118+
}
119+
116120
if (null !== $expiry && $expiry <= time()) {
117121
$this->deleteItem($key);
118122

src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\MockObject\MockObject;
1515
use Psr\Cache\CacheItemInterface;
1616
use Symfony\Component\Cache\Adapter\AdapterInterface;
17+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
1718
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
1819
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
1920

@@ -255,6 +256,25 @@ public function testHasItemReturnsFalseWhenPoolDoesNotHaveItemAndOnlyHasTags()
255256
$this->assertFalse($anotherPool->hasItem($itemKey));
256257
}
257258

259+
public function testInvalidateTagsWithArrayAdapter()
260+
{
261+
$adapter = new TagAwareAdapter(new ArrayAdapter());
262+
263+
$item = $adapter->getItem('foo');
264+
265+
$this->assertFalse($item->isHit());
266+
267+
$item->tag('bar');
268+
$item->expiresAfter(100);
269+
$adapter->save($item);
270+
271+
$this->assertTrue($adapter->getItem('foo')->isHit());
272+
273+
$adapter->invalidateTags(['bar']);
274+
275+
$this->assertFalse($adapter->getItem('foo')->isHit());
276+
}
277+
258278
public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemAndOnlyHasTags()
259279
{
260280
$pool = $this->createCachePool();

0 commit comments

Comments
 (0)
0