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, $defaultLifetime / 5, $version); if (null !== $logger) { $apcu->setLogger($logger); } return new ChainAdapter(array($apcu, $fs)); }
public function testNonce() { $namespace = str_replace('\\', '.', __CLASS__); $pool1 = new ApcuAdapter($namespace, 0, 'p1'); $item = $pool1->getItem('foo'); $this->assertFalse($item->isHit()); $this->assertTrue($pool1->save($item->set('bar'))); $item = $pool1->getItem('foo'); $this->assertTrue($item->isHit()); $this->assertSame('bar', $item->get()); $pool2 = new ApcuAdapter($namespace, 0, 'p2'); $item = $pool2->getItem('foo'); $this->assertFalse($item->isHit()); $this->assertNull($item->get()); $item = $pool1->getItem('foo'); $this->assertFalse($item->isHit()); $this->assertNull($item->get()); }
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; }