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

Commit 89ba875

Browse filesBrowse files
[Cache] Handle APCu failures gracefully
1 parent ddc9d2e commit 89ba875
Copy full SHA for 89ba875

File tree

2 files changed

+6
-3
lines changed
Filter options

2 files changed

+6
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
+4-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Adapter/ApcuAdapter.php
+2-2Lines changed: 2 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,7 @@ 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+
return array_keys(apcu_store($values, null, $lifetime) ?: $values);
9696
} catch (\Error $e) {
9797
} catch (\Exception $e) {
9898
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.