-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Cache] Handle APCu failures gracefully #23390
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,7 +50,7 @@ public function __construct($namespace = '', $defaultLifetime = 0, $version = nu | |
protected function doFetch(array $ids) | ||
{ | ||
try { | ||
return apcu_fetch($ids); | ||
return apcu_fetch($ids) ?: array(); | ||
} catch (\Error $e) { | ||
throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine()); | ||
} | ||
|
@@ -92,7 +92,11 @@ protected function doDelete(array $ids) | |
protected function doSave(array $values, $lifetime) | ||
{ | ||
try { | ||
return array_keys(apcu_store($values, null, $lifetime)); | ||
if (false === $failures = apcu_store($values, null, $lifetime)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, do you guys treat is a good-practice coding style? Most of linting tools warn you about assignments being done inside the conditional statements. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes ... we decided a long ago (in 2011 if I remember correctly) to use Yoda-style conditions. I don't think we can change this now, because it will be a nightmare for our mergers. |
||
$failures = $values; | ||
} | ||
|
||
return array_keys($failures); | ||
} catch (\Error $e) { | ||
} catch (\Exception $e) { | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we pass the
NullLogger
here? Why do we just not callsetLogger()
instead?Like this:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because when no logger is set, failures are still "logged" here:
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/CacheItem.php#L182
but we really want to silence.