Skip to content

Commit f8a8eb1

Browse files
Add reproducer to for hit after update expire cacheItem
1 parent 39a7ee1 commit f8a8eb1

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/Symfony/Component/Cache/Tests/Traits/TagAwareTestTrait.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,42 @@ public function testGetMetadata()
155155
$i = $pool->getItem('k');
156156
$this->assertSame(['foo' => 'foo'], $i->getMetadata()[CacheItem::METADATA_TAGS]);
157157
}
158+
159+
public function testRefreshAfterExpires()
160+
{
161+
$pool = $this->createCachePool();
162+
$pool->clear();
163+
164+
$cacheItem = $pool->getItem('test');
165+
166+
$this->assertFalse($cacheItem->isHit());
167+
168+
// write cache with expires
169+
$cacheItem->set('test');
170+
$cacheItem->tag('1234');
171+
$cacheItem->expiresAfter(5);
172+
173+
$pool->save($cacheItem);
174+
175+
$cacheItem = $pool->getItem('test');
176+
$this->assertTrue($cacheItem->isHit());
177+
178+
// wait until expired
179+
sleep(5);
180+
181+
// item should not longer be a hit
182+
$cacheItem = $pool->getItem('test');
183+
$this->assertFalse($cacheItem->isHit());
184+
185+
// update expired item
186+
$cacheItem->set('test');
187+
$cacheItem->tag('1234');
188+
$cacheItem->expiresAfter(5);
189+
190+
$pool->save($cacheItem);
191+
192+
// item should be again a hit
193+
$cacheItem = $pool->getItem('test');
194+
$this->assertTrue($cacheItem->isHit());
195+
}
158196
}

0 commit comments

Comments
 (0)