Add reproducer to for hit after update expire cacheItem

This commit is contained in:
Alexander Schranz 2020-04-15 14:44:16 +02:00 committed by Nicolas Grekas
parent f815b011c3
commit d082eca7dd

View File

@ -155,4 +155,42 @@ trait TagAwareTestTrait
$i = $pool->getItem('k');
$this->assertSame(['foo' => 'foo'], $i->getMetadata()[CacheItem::METADATA_TAGS]);
}
public function testRefreshAfterExpires()
{
$pool = $this->createCachePool();
$pool->clear();
$cacheItem = $pool->getItem('test');
$this->assertFalse($cacheItem->isHit());
// write cache with expires
$cacheItem->set('test');
$cacheItem->tag('1234');
$cacheItem->expiresAfter(1);
$pool->save($cacheItem);
$cacheItem = $pool->getItem('test');
$this->assertTrue($cacheItem->isHit());
// wait until expired
sleep(2);
// item should not longer be a hit
$cacheItem = $pool->getItem('test');
$this->assertFalse($cacheItem->isHit());
// update expired item
$cacheItem->set('test');
$cacheItem->tag('1234');
$cacheItem->expiresAfter(1);
$pool->save($cacheItem);
// item should be again a hit
$cacheItem = $pool->getItem('test');
$this->assertTrue($cacheItem->isHit());
}
}