Skip to content

Commit 4a02c88

Browse files
committed
minor symfony#18992 [Cache] AbstractAdapter: avoid an extra call to ApcuAdapter::isSupported (dunglas)
This PR was squashed before being merged into the 3.2-dev branch (closes symfony#18992). Discussion ---------- [Cache] AbstractAdapter: avoid an extra call to ApcuAdapter::isSupported | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Commits ------- 8f2ea52 [Cache] AbstractAdapter: avoid an extra call to ApcuAdapter::isSupported
2 parents 8cf922c + 8f2ea52 commit 4a02c88

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface
2424
{
2525
use LoggerAwareTrait;
2626

27+
private static $apcuSupported;
28+
private static $phpFilesSupported;
29+
2730
private $namespace;
2831
private $deferred = array();
2932
private $createCacheItem;
@@ -70,7 +73,15 @@ function ($deferred, $namespace, &$expiredIds) {
7073

7174
public static function createSystemCache($namespace, $defaultLifetime, $version, $directory, LoggerInterface $logger = null)
7275
{
73-
if (!ApcuAdapter::isSupported() && PhpFilesAdapter::isSupported()) {
76+
if (null === self::$apcuSupported) {
77+
self::$apcuSupported = ApcuAdapter::isSupported();
78+
}
79+
80+
if (!self::$apcuSupported && null === self::$phpFilesSupported) {
81+
self::$phpFilesSupported = PhpFilesAdapter::isSupported();
82+
}
83+
84+
if (self::$phpFilesSupported) {
7485
$opcache = new PhpFilesAdapter($namespace, $defaultLifetime, $directory);
7586
if (null !== $logger) {
7687
$opcache->setLogger($logger);
@@ -83,7 +94,7 @@ public static function createSystemCache($namespace, $defaultLifetime, $version,
8394
if (null !== $logger) {
8495
$fs->setLogger($logger);
8596
}
86-
if (!ApcuAdapter::isSupported()) {
97+
if (!self::$apcuSupported) {
8798
return $fs;
8899
}
89100

0 commit comments

Comments
 (0)