Skip to content

Commit

Permalink
[Cache] skip APCu in chains when the backend is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Apr 23, 2020
1 parent 08ded7f commit 68528f8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/Symfony/Component/Cache/Adapter/AbstractAdapter.php
Expand Up @@ -116,14 +116,12 @@ public static function createSystemCache($namespace, $defaultLifetime, $version,
if (null !== $logger) {
$fs->setLogger($logger);
}
if (!self::$apcuSupported) {
if (!self::$apcuSupported || (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN))) {
return $fs;
}

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

Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Cache/Adapter/ChainAdapter.php
Expand Up @@ -46,6 +46,9 @@ public function __construct(array $adapters, $defaultLifetime = 0)
if (!$adapter instanceof CacheItemPoolInterface) {
throw new InvalidArgumentException(sprintf('The class "%s" does not implement the "%s" interface.', \get_class($adapter), CacheItemPoolInterface::class));
}
if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && $adapter instanceof ApcuAdapter && !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN)) {
continue; // skip putting APCu in the chain when the backend is disabled
}

if ($adapter instanceof AdapterInterface) {
$this->adapters[] = $adapter;
Expand Down

0 comments on commit 68528f8

Please sign in to comment.