public static function createSystemCache($namespace, $defaultLifetime, $version, $directory, LoggerInterface $logger = null) { 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); } return $opcache; } $fs = new FilesystemAdapter($namespace, $defaultLifetime, $directory); if (null !== $logger) { $fs->setLogger($logger); } if (!self::$apcuSupported) { return $fs; } $apcu = new ApcuAdapter($namespace, (int) $defaultLifetime / 5, $version); if (null !== $logger) { $apcu->setLogger($logger); } return new ChainAdapter(array($apcu, $fs)); }
public static function createSystemCache($namespace, $defaultLifetime, $nonce, $directory, LoggerInterface $logger = null) { $fs = new FilesystemAdapter($namespace, $defaultLifetime, $directory); if (null !== $logger) { $fs->setLogger($logger); } if (!ApcuAdapter::isSupported()) { return $fs; } $apcu = new ApcuAdapter($namespace, $defaultLifetime / 5, $nonce); if (null !== $logger) { $apcu->setLogger($logger); } return new ChainAdapter(array($apcu, $fs)); }
/** * Creates the APCu adapter if applicable. * * @param string $namespace * @param int $defaultLifetime * @param string $version * @param LoggerInterface|null $logger * * @return AdapterInterface * * @throws RuntimeException When the Cache Component isn't available */ public static function createCache($namespace, $defaultLifetime, $version, LoggerInterface $logger = null) { if (!class_exists('Symfony\\Component\\Cache\\Adapter\\ApcuAdapter')) { throw new \RuntimeException(sprintf('The Symfony Cache component must be installed to use %s().', __METHOD__)); } if (!ApcuAdapter::isSupported()) { return new NullAdapter(); } $apcu = new ApcuAdapter($namespace, $defaultLifetime / 5, $version); if (null !== $logger) { $apcu->setLogger($logger); } return $apcu; }