8000 [Cache] Handle APCu failures gracefully · symfony/symfony@47020c4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 47020c4

Browse files
[Cache] Handle APCu failures gracefully
1 parent ddc9d2e commit 47020c4

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Symfony/Component/Cache/Adapter/AbstractAdapter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Psr\Log\LoggerAwareInterface;
1616
use Psr\Log\LoggerAwareTrait;
1717
use Psr\Log\LoggerInterface;
18+
use Psr\Log\NullLogger;
1819
use Symfony\Component\Cache\CacheItem;
1920
use Symfony\Component\Cache\Exception\InvalidArgumentException;
2021

@@ -108,7 +109,9 @@ public static function createSystemCache($namespace, $defaultLifetime, $version,
108109
}
109110

110111
$apcu = new ApcuAdapter($namespace, (int) $defaultLifetime / 5, $version);
111-
if (null !== $logger) {
112+
if ('cli' === PHP_SAPI && !ini_get('apc.enable_cli')) {
113+
$apcu->setLogger(new NullLogger());
114+
} elseif (null !== $logger) {
112115
$apcu->setLogger($logger);
113116
}
114117

src/Symfony/Component/Cache/Adapter/ApcuAdapter.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct($namespace = '', $defaultLifetime = 0, $version = nu
5050
protected function doFetch(array $ids)
5151
{
5252
try {
53-
return apcu_fetch($ids);
53+
return apcu_fetch($ids) ?: array();
5454
} catch (\Error $e) {
5555
throw new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
5656
}
@@ -92,7 +92,11 @@ protected function doDelete(array $ids)
9292
protected function doSave(array $values, $lifetime)
9393
{
9494
try {
95-
return array_keys(apcu_store($values, null, $lifetime));
95+
if (false === $failures = apcu_store($values, null, $lifetime)) {
96+
$failures = $values;
97+
}
98+
99+
return array_keys($failures);
96100
} catch (\Error $e) {
97101
} catch (\Exception $e) {
98102
}

0 commit comments

Comments
 (0)
0