示例#1
0
 /**
  * @param string $namespace
  * @param string $identifier
  * @param array  $options
  */
 public function __construct($namespace, $identifier, array $options)
 {
     parent::__construct($namespace, $identifier, $options);
     $this->prefix = $namespace . '.' . $identifier . '.';
     if (isset($options['ttl'])) {
         $this->ttl = $options['ttl'];
     }
 }
示例#2
0
 /**
  * @param string $namespace
  * @param string $identifier
  * @param array $options
  * @throws \InvalidArgumentException
  * @throws \Leapt\CacheBundle\Exception\CacheException
  */
 public function __construct($namespace, $identifier, array $options)
 {
     parent::__construct($namespace, $identifier, $options);
     $this->driver = new \Memcached();
     $this->driver->setOption(\Memcached::OPT_PREFIX_KEY, $namespace . '.' . $identifier . '.');
     if (!isset($options['server']) || !isset($options['port'])) {
         throw new \InvalidArgumentException(sprintf('Memcached is expecting a "server" and "port" options'));
     }
     if (!$this->driver->addServer($options['server'], $options['port'])) {
         throw new CacheException('The memcached server could not be added');
     }
     if (isset($options['ttl'])) {
         $this->ttl = $options['ttl'];
     }
 }