minor #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 #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
This commit is contained in:
Fabien Potencier 2016-06-08 12:08:58 +02:00
commit 4a02c8832c
1 changed files with 13 additions and 2 deletions

View File

@ -24,6 +24,9 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface
{
use LoggerAwareTrait;
private static $apcuSupported;
private static $phpFilesSupported;
private $namespace;
private $deferred = array();
private $createCacheItem;
@ -70,7 +73,15 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface
public static function createSystemCache($namespace, $defaultLifetime, $version, $directory, LoggerInterface $logger = null)
{
if (!ApcuAdapter::isSupported() && PhpFilesAdapter::isSupported()) {
if (null === self::$apcuSupported) {
self::$apcuSupported = ApcuAdapter::isSupported();
}
if (!self::$apcuSupported && null === self::$phpFilesSupported) {
self::$phpFilesSupported = PhpFilesAdapter::isSupported();
}
if (self::$phpFilesSupported) {
$opcache = new PhpFilesAdapter($namespace, $defaultLifetime, $directory);
if (null !== $logger) {
$opcache->setLogger($logger);
@ -83,7 +94,7 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface
if (null !== $logger) {
$fs->setLogger($logger);
}
if (!ApcuAdapter::isSupported()) {
if (!self::$apcuSupported) {
return $fs;
}