Skip to content

Commit

Permalink
Add reproducer to for hit after update expire cacheItem
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed Apr 15, 2020
1 parent 39a7ee1 commit f8a8eb1
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Symfony/Component/Cache/Tests/Traits/TagAwareTestTrait.php
Expand Up @@ -155,4 +155,42 @@ public function testGetMetadata()
$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(5);

$pool->save($cacheItem);

$cacheItem = $pool->getItem('test');
$this->assertTrue($cacheItem->isHit());

// wait until expired
sleep(5);

// 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(5);

$pool->save($cacheItem);

// item should be again a hit
$cacheItem = $pool->getItem('test');
$this->assertTrue($cacheItem->isHit());
}
}

0 comments on commit f8a8eb1

Please sign in to comment.