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] 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

Merged
merged 1 commit into from
Jul 5, 2017
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
5 changes: 4 additions & 1 deletion 5 src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\Cache\CacheItem;
use Symfony\Component\Cache\Exception\InvalidArgumentException;

Expand Down Expand Up @@ -108,7 +109,9 @@ public static function createSystemCache($namespace, $defaultLifetime, $version,
}

$apcu = new ApcuAdapter($namespace, (int) $defaultLifetime / 5, $version);
if (null !== $logger) {
if ('cli' === PHP_SAPI && !ini_get('apc.enable_cli')) {
$apcu->setLogger(new NullLogger());
} elseif (null !== $logger) {
Copy link
Member

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 call setLogger() instead?

Like this:

if (null !== $logger && ('cli' !== PHP_SAPI || ini_get('apc.enable_cli'))) {
    // ...
}

Copy link
Member Author

@nicolas-grekas nicolas-grekas Jul 4, 2017

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.

$apcu->setLogger($logger);
}

Expand Down
8 changes: 6 additions & 2 deletions 8 src/Symfony/Component/Cache/Adapter/ApcuAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down Expand Up @@ -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)) {
Copy link

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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) {
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.