Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cache] CacheItem with tag is never a hit after expired #36457

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -107,7 +107,7 @@ protected function doSave(array $values, ?int $lifetime, array $addTagData = [],

$file = $this->getFile($id);

if (!@symlink($file, $this->getFile($id, true, $tagFolder))) {
if (!@symlink($file, $tagLink = $this->getFile($id, true, $tagFolder)) && !is_link($tagLink)) {
@unlink($file);
$failed[] = $id;
}
Expand Down
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(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());
}
}