public function __construct($namespace = '', $defaultLifetime = 0, $directory = null) { parent::__construct('', $defaultLifetime); if (!isset($directory[0])) { $directory = sys_get_temp_dir() . '/symfony-cache'; } if (isset($namespace[0])) { if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) { throw new InvalidArgumentException(sprintf('FilesystemAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0])); } $directory .= '/' . $namespace; } if (!file_exists($dir = $directory . '/.')) { @mkdir($directory, 0777, true); } if (false === ($dir = realpath($dir))) { throw new InvalidArgumentException(sprintf('Cache directory does not exist (%s)', $directory)); } if (!is_writable($dir .= DIRECTORY_SEPARATOR)) { throw new InvalidArgumentException(sprintf('Cache directory is not writable (%s)', $directory)); } // On Windows the whole path is limited to 258 chars if ('\\' === DIRECTORY_SEPARATOR && strlen($dir) > 234) { throw new InvalidArgumentException(sprintf('Cache directory too long (%s)', $directory)); } $this->directory = $dir; }
public function __construct(\Redis $redisConnection, $namespace = '', $defaultLifetime = 0) { $this->redis = $redisConnection; if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) { throw new InvalidArgumentException(sprintf('RedisAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0])); } parent::__construct($namespace, $defaultLifetime); }
public function __construct($namespace = '', $defaultLifetime = 0) { if (!function_exists('apcu_fetch') || !ini_get('apc.enabled') || 'cli' === PHP_SAPI && !ini_get('apc.enable_cli')) { throw new CacheException('APCu is not enabled'); } if ('cli' === PHP_SAPI) { ini_set('apc.use_request_time', 0); } parent::__construct($namespace, $defaultLifetime); }
/** * @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redisClient */ public function __construct($redisClient, $namespace = '', $defaultLifetime = 0) { parent::__construct($namespace, $defaultLifetime); if (preg_match('#[^-+_.A-Za-z0-9]#', $namespace, $match)) { throw new InvalidArgumentException(sprintf('RedisAdapter namespace contains "%s" but only characters in [-+_.A-Za-z0-9] are allowed.', $match[0])); } if (!$redisClient instanceof \Redis && !$redisClient instanceof \RedisArray && !$redisClient instanceof \RedisCluster && !$redisClient instanceof \Predis\Client) { throw new InvalidArgumentException(sprintf('%s() expects parameter 1 to be Redis, RedisArray, RedisCluster or Predis\\Client, %s given', __METHOD__, is_object($redisClient) ? get_class($redisClient) : gettype($redisClient))); } $this->redis = $redisClient; }
public function __construct($namespace = '', $defaultLifetime = 0, $directory = null) { if (!static::isSupported()) { throw new CacheException('OPcache is not enabled'); } parent::__construct('', $defaultLifetime); $this->init($namespace, $directory); $e = new \Exception(); $this->includeHandler = function () use($e) { throw $e; }; }
public function __construct($namespace = '', $defaultLifetime = 0, $version = null) { if (!static::isSupported()) { throw new CacheException('APCu is not enabled'); } if ('cli' === PHP_SAPI) { ini_set('apc.use_request_time', 0); } parent::__construct($namespace, $defaultLifetime); if (null !== $version) { CacheItem::validateKey($version); if (!apcu_exists($version . ':' . $namespace)) { $this->clear($namespace); apcu_add($version . ':' . $namespace, null); } } }
public function __construct($directory, $defaultLifetime = null) { parent::__construct('', $defaultLifetime); if (!file_exists($dir = $directory . '/.')) { @mkdir($directory, 0777, true); } if (false === ($dir = realpath($dir))) { throw new InvalidArgumentException(sprintf('Cache directory does not exist (%s)', $directory)); } if (!is_writable($dir .= DIRECTORY_SEPARATOR)) { throw new InvalidArgumentException(sprintf('Cache directory is not writable (%s)', $directory)); } // On Windows the whole path is limited to 258 chars if ('\\' === DIRECTORY_SEPARATOR && strlen($dir) > 190) { throw new InvalidArgumentException(sprintf('Cache directory too long (%s)', $directory)); } $this->directory = $dir; }
public function __construct($directory, $defaultLifetime = 0, $namespace = '') { parent::__construct('', $defaultLifetime); if (!isset($directory[0])) { $directory = sys_get_temp_dir() . '/symfony-cache'; } if (isset($namespace[0])) { $directory .= '/' . $namespace; } if (!file_exists($dir = $directory . '/.')) { @mkdir($directory, 0777, true); } if (false === ($dir = realpath($dir))) { throw new InvalidArgumentException(sprintf('Cache directory does not exist (%s)', $directory)); } if (!is_writable($dir .= DIRECTORY_SEPARATOR)) { throw new InvalidArgumentException(sprintf('Cache directory is not writable (%s)', $directory)); } // On Windows the whole path is limited to 258 chars if ('\\' === DIRECTORY_SEPARATOR && strlen($dir) > 234) { throw new InvalidArgumentException(sprintf('Cache directory too long (%s)', $directory)); } $this->directory = $dir; }
/** * @param \Redis|\RedisArray|\RedisCluster|\Predis\Client $redisClient */ public function __construct($redisClient, $namespace = '', $defaultLifetime = 0) { parent::__construct($namespace, $defaultLifetime); $this->setRedis($redisClient, $namespace); }
protected function getCache_ValidatorService() { return $this->services['cache.validator'] = \Symfony\Component\Cache\Adapter\AbstractAdapter::createSystemCache('VX19+IbeIt', 0, 'imC54TDz8E4mrPrZvIMSee', __DIR__ . '/pools', $this->get('monolog.logger.cache', ContainerInterface::NULL_ON_INVALID_REFERENCE)); }
public function __construct(CacheProvider $provider, $defaultLifetime = null) { parent::__construct('', $defaultLifetime); $this->provider = $provider; }
/** * Gets the 'cache_clearer' service. * * This service is shared. * This method always returns the same instance of the service. * * @return \Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer A Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer instance */ protected function getCacheClearerService() { $a = $this->get('monolog.logger.cache', ContainerInterface::NULL_ON_INVALID_REFERENCE); $b = new \Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer(); $b->addPool($this->get('cache.app')); $b->addPool($this->get('cache.system')); $b->addPool(\Symfony\Component\Cache\Adapter\AbstractAdapter::createSystemCache('7Wzv1NQ5ZT', 0, 'foxwjzf+icTDS30G8qOorH', __DIR__ . '/pools', $a)); $b->addPool(\Symfony\Component\Cache\Adapter\AbstractAdapter::createSystemCache('fCYpcz2wbV', 0, 'foxwjzf+icTDS30G8qOorH', __DIR__ . '/pools', $a)); return $this->services['cache_clearer'] = new \Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer(array(0 => $b)); }
/** * Gets the 'cache.annotations' service. * * This service is shared. * This method always returns the same instance of the service. * * This service is private. * If you want to be able to request this service from the container directly, * make it public, otherwise you might end up with broken code. * * @return \Symfony\Component\Cache\Adapter\AdapterInterface A Symfony\Component\Cache\Adapter\AdapterInterface instance */ protected function getCache_AnnotationsService() { return $this->services['cache.annotations'] = \Symfony\Component\Cache\Adapter\AbstractAdapter::createSystemCache('GemRP2koiI', 0, 'kYH8hP4PfdP8SU3P7jSqTZ', __DIR__ . '/pools', $this->get('monolog.logger.cache')); }
protected function getCache_ValidatorService() { return $this->services['cache.validator'] = \Symfony\Component\Cache\Adapter\AbstractAdapter::createSystemCache('a15L71WfPV', 0, '4ECvTrOM7vS+gfVOWsq5Yg', __DIR__ . '/pools', $this->get('monolog.logger.cache', ContainerInterface::NULL_ON_INVALID_REFERENCE)); }
public function __construct($ns) { parent::__construct($ns); }
/** * Gets the 'cache_clearer' service. * * This service is shared. * This method always returns the same instance of the service. * * @return \Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer A Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer instance */ protected function getCacheClearerService() { $a = $this->get('monolog.logger.cache', ContainerInterface::NULL_ON_INVALID_REFERENCE); $b = new \Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer(); $b->addPool($this->get('cache.app')); $b->addPool($this->get('cache.system')); $b->addPool(\Symfony\Component\Cache\Adapter\AbstractAdapter::createSystemCache('5JrRbfcn8g', 0, '0LYrQxhfnNv0bpRxbcBdRB', __DIR__ . '/pools', $a)); $b->addPool(\Symfony\Component\Cache\Adapter\AbstractAdapter::createSystemCache('KV6uHM-gsG', 0, '0LYrQxhfnNv0bpRxbcBdRB', __DIR__ . '/pools', $a)); return $this->services['cache_clearer'] = new \Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer(array(0 => $b)); }
/** * Gets the 'cache.annotations' service. * * This service is shared. * This method always returns the same instance of the service. * * This service is private. * If you want to be able to request this service from the container directly, * make it public, otherwise you might end up with broken code. * * @return \Symfony\Component\Cache\Adapter\AdapterInterface A Symfony\Component\Cache\Adapter\AdapterInterface instance */ protected function getCache_AnnotationsService() { return $this->services['cache.annotations'] = \Symfony\Component\Cache\Adapter\AbstractAdapter::createSystemCache('AzAC+eWen6', 0, 'dwqEoKLi3SF+xZmlznlKHJ', __DIR__ . '/pools', $this->get('monolog.logger.cache')); }
/** * Gets the 'cache_clearer' service. * * This service is shared. * This method always returns the same instance of the service. * * @return \Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer A Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer instance */ protected function getCacheClearerService() { $a = $this->get('monolog.logger.cache', ContainerInterface::NULL_ON_INVALID_REFERENCE); $b = new \Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer(); $b->addPool($this->get('cache.app')); $b->addPool($this->get('cache.system')); $b->addPool(\Symfony\Component\Cache\Adapter\AbstractAdapter::createSystemCache('rtz3BU4xTF', 0, '4MqbYEBygVQcYcqZi36erA', __DIR__ . '/pools', $a)); $b->addPool(\Symfony\Component\Cache\Adapter\AbstractAdapter::createSystemCache('asbzMtyRcS', 0, '4MqbYEBygVQcYcqZi36erA', __DIR__ . '/pools', $a)); return $this->services['cache_clearer'] = new \Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer(array(0 => $b)); }
/** * {@inheritdoc} */ protected function doSave(array $values, $lifetime) { $ok = true; $data = array($lifetime ? time() + $lifetime : PHP_INT_MAX, ''); $allowCompile = 'cli' !== PHP_SAPI || ini_get('opcache.enable_cli'); foreach ($values as $key => $value) { if (null === $value || is_object($value)) { $value = serialize($value); } elseif (is_array($value)) { $serialized = serialize($value); $unserialized = parent::unserialize($serialized); // Store arrays serialized if they contain any objects or references if ($unserialized !== $value || false !== strpos($serialized, ';R:') && preg_match('/;R:[1-9]/', $serialized)) { $value = $serialized; } } elseif (is_string($value)) { // Serialize strings if they could be confused with serialized objects or arrays if ('N;' === $value || isset($value[2]) && ':' === $value[1]) { $value = serialize($value); } } elseif (!is_scalar($value)) { throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, gettype($value))); } $data[1] = $value; $file = $this->getFile($key, true); $ok = $this->write($file, '<?php return ' . var_export($data, true) . ';') && $ok; if ($allowCompile) { @opcache_compile_file($file); } } return $ok; }
public function __construct(CacheProvider $provider, $namespace = '', $defaultLifetime = 0) { parent::__construct('', $defaultLifetime); $this->provider = $provider; $provider->setNamespace($namespace); }
protected function getCache_ValidatorService() { return $this->services['cache.validator'] = \Symfony\Component\Cache\Adapter\AbstractAdapter::createSystemCache('m1Mv17Lmdf', 0, 'UkBkIRCe1JsnvZInlSXGVA', __DIR__ . '/pools', $this->get('monolog.logger.cache', ContainerInterface::NULL_ON_INVALID_REFERENCE)); }
/** * {@inheritdoc} */ protected function doFetch(array $ids) { if ($ids) { $values = $this->redis->mGet($ids); $index = 0; foreach ($ids as $id) { if ($value = $values[$index++]) { (yield $id => parent::unserialize($value)); } } } }
/** * {@inheritdoc} */ protected function doFetch(array $ids) { $now = time(); $expired = array(); $sql = str_pad('', (count($ids) << 1) - 1, '?,'); $sql = "SELECT {$this->idCol}, CASE WHEN {$this->lifetimeCol} IS NULL OR {$this->lifetimeCol} + {$this->timeCol} > ? THEN {$this->dataCol} ELSE NULL END FROM {$this->table} WHERE {$this->idCol} IN ({$sql})"; $stmt = $this->getConnection()->prepare($sql); $stmt->bindValue($i = 1, $now, \PDO::PARAM_INT); foreach ($ids as $id) { $stmt->bindValue(++$i, $id); } $stmt->execute(); while ($row = $stmt->fetch(\PDO::FETCH_NUM)) { if (null === $row[1]) { $expired[] = $row[0]; } else { (yield $row[0] => parent::unserialize(is_resource($row[1]) ? stream_get_contents($row[1]) : $row[1])); } } if ($expired) { $sql = str_pad('', (count($expired) << 1) - 1, '?,'); $sql = "DELETE FROM {$this->table} WHERE {$this->lifetimeCol} + {$this->timeCol} <= ? AND {$this->idCol} IN ({$sql})"; $stmt = $this->getConnection()->prepare($sql); $stmt->bindValue($i = 1, $now, \PDO::PARAM_INT); foreach ($expired as $id) { $stmt->bindValue(++$i, $id); } $stmt->execute($expired); } }