Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Cache] fixed TagAwareAdapter returning invalid cache #33962

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Cache] fixed TagAwareAdapter returning invalid cache
  • Loading branch information
v-m-i authored and nicolas-grekas committed Oct 12, 2019
commit 946f0a1e11e5182364d42b323fa82df3212be591
12 changes: 10 additions & 2 deletions 12 src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ public function hasItem($key)
if (!$this->pool->hasItem($key)) {
return false;
}
if (!$itemTags = $this->pool->getItem(static::TAGS_PREFIX.$key)->get()) {

if (!($itemTags = $this->pool->getItem(static::TAGS_PREFIX.$key))->isHit()) {
return false;
}

if (!$itemTags = $itemTags->get()) {
return true;
}

Expand Down Expand Up @@ -296,7 +301,10 @@ private function generateItems($items, array $tagKeys)
}

unset($tagKeys[$key]);
$itemTags[$key] = $item->get() ?: [];

if ($item->isHit()) {
$itemTags[$key] = $item->get() ?: [];
}

if (!$tagKeys) {
$tagVersions = $this->getTagVersions($itemTags);
Expand Down
78 changes: 78 additions & 0 deletions 78 src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,84 @@ public function testKnownTagVersionsTtl()
$this->assertTrue($pool->getItem('foo')->isHit());
}

public function testTagEntryIsCreatedForItemWithoutTags()
{
$pool = $this->createCachePool();

$itemKey = 'foo';
$item = $pool->getItem($itemKey);
$pool->save($item);

$adapter = new FilesystemAdapter();
$this->assertTrue($adapter->hasItem(TagAwareAdapter::TAGS_PREFIX.$itemKey));
}

public function testHasItemReturnsFalseWhenPoolDoesNotHaveItemTags()
{
$pool = $this->createCachePool();

$itemKey = 'foo';
$item = $pool->getItem($itemKey);
$pool->save($item);

$anotherPool = $this->createCachePool();

$adapter = new FilesystemAdapter();
$adapter->deleteItem(TagAwareAdapter::TAGS_PREFIX.$itemKey); //simulate item losing tags pair

$this->assertFalse($anotherPool->hasItem($itemKey));
}

public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemTags()
{
$pool = $this->createCachePool();

$itemKey = 'foo';
$item = $pool->getItem($itemKey);
$pool->save($item);

$anotherPool = $this->createCachePool();

$adapter = new FilesystemAdapter();
$adapter->deleteItem(TagAwareAdapter::TAGS_PREFIX.$itemKey); //simulate item losing tags pair

$item = $anotherPool->getItem($itemKey);
$this->assertFalse($item->isHit());
}

public function testHasItemReturnsFalseWhenPoolDoesNotHaveItemAndOnlyHasTags()
{
$pool = $this->createCachePool();

$itemKey = 'foo';
$item = $pool->getItem($itemKey);
$pool->save($item);

$anotherPool = $this->createCachePool();

$adapter = new FilesystemAdapter();
$adapter->deleteItem($itemKey); //simulate losing item but keeping tags

$this->assertFalse($anotherPool->hasItem($itemKey));
}

public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemAndOnlyHasTags()
{
$pool = $this->createCachePool();

$itemKey = 'foo';
$item = $pool->getItem($itemKey);
$pool->save($item);

$anotherPool = $this->createCachePool();

$adapter = new FilesystemAdapter();
$adapter->deleteItem($itemKey); //simulate losing item but keeping tags

$item = $anotherPool->getItem($itemKey);
$this->assertFalse($item->isHit());
}

/**
* @return MockObject|PruneableCacheInterface
*/
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.