public function testConstructionOptions() { $key = array('apple', 'sauce'); $options = array(); $options['servers'][] = array('127.0.0.1', '11211', '50'); $options['servers'][] = array('127.0.0.1', '11211'); $options['extension'] = $this->extension; $driver = new Memcache(); $driver->setOptions($options); $item = new Item(); $poolStub = new PoolGetDriverStub(); $poolStub->setDriver($driver); $item->setPool($poolStub); $item->setKey($key); $this->assertTrue($item->set($key), 'Able to load and store memcache driver using multiple servers'); $options = array(); $options['extension'] = $this->extension; $driver = new Memcache(); $driver->setOptions($options); $item = new Item(); $poolStub = new PoolGetDriverStub(); $poolStub->setDriver($driver); $item->setPool($poolStub); $item->setKey($key); $this->assertTrue($item->set($key), 'Able to load and store memcache driver using default server'); }
public function testConstruction() { $key = array('apple', 'sauce'); $options = array(); $options['servers'][] = array('127.0.0.1', '11211', '50'); $driver = new Memcache(); $driver->setOptions($options); $item = new Item(); $poolStub = new PoolGetDriverStub(); $poolStub->setDriver($driver); $item->setPool($poolStub); $item->setKey($key); $this->assertTrue($item->set($key), 'Able to load and store with unconfigured extension.'); }
/** * Builds cache pool instance. * * @todo Most likely the factory should return Ephemeral cache if a real * storage cannot be used by some resons. * * @return PoolInterface An instance of cache pool. * @throws \RuntimeException If at least one of factory's options is * invalid. */ public function getCache() { if (is_null($this->cache)) { $storage = $this->getOption('storage'); if ($storage === 'none') { $driver = new EphemeralDriver(); } elseif ($storage === 'file_system') { $driver = new FileSystemDriver(); $driver->setOptions(array('path' => $this->getOption('path'))); } elseif ($storage === 'memcached') { $servers = $this->getOption('memcached_servers'); // Make sure memcached servers was described correctly. The next // statement will throw Exception if something is wrong so we do // not need to check the result. $this->validateMemcachedServers($servers); // Convert structure from the "memcached_servers" option to the // form used in cache driver. $formated_servers = array_map(function ($server) { return array($server['host'], intval($server['port']), isset($server['weight']) ? intval($server['weight']) : 0); }, $servers); $driver = new MemcacheDriver(); $driver->setOptions(array('servers' => $formated_servers, 'extension' => 'memcached')); } else { throw new \RuntimeException(sprintf('Wrong value of "storage" option: "%s"', $storage)); } $this->cache = new CachePool($driver); } return $this->cache; }
public function __construct() { $driver = new Memcache(); $driver->setOptions(Config::get('concrete.cache.page.memcached')); self::$pool = new Pool($driver); }