Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Cache] Workaround krakjoe/apcu#170 #18485

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
Apr 12, 2016
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
13 changes: 12 additions & 1 deletion src/Symfony/Component/Cache/Adapter/ApcuAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ protected function doDelete(array $ids)
*/
protected function doSave(array $values, $lifetime)
{
return array_keys(apcu_store($values, null, $lifetime));
try {
return array_keys(apcu_store($values, null, $lifetime));
} catch (\Error $e) {
} catch (\Exception $e) {
}

if (1 === count($values)) {
// Workaround https://github.com/krakjoe/apcu/issues/170
apcu_delete(key($values));
}

throw $e;
}
}
13 changes: 13 additions & 0 deletions src/Symfony/Component/Cache/Tests/Adapter/ApcuAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,17 @@ public function createCachePool()

return new ApcuAdapter(str_replace('\\', '.', __CLASS__));
}

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

$item = $pool->getItem('foo');
$item->set(function() {});

$this->assertFalse($pool->save($item));

$item = $pool->getItem('foo');
$this->assertFalse($item->isHit());
}
}