/** * Return memcache connection object * * @return object memcache connection object * * @since 11.1 * @throws RuntimeException */ protected function getConnection() { if ((extension_loaded('memcache') && class_exists('Memcache')) != true) { return false; } $config = JFactory::getConfig(); $this->_persistent = $config->get('memcache_persist', true); $this->_compress = $config->get('memcache_compress', false) == false ? 0 : MEMCACHE_COMPRESSED; /* * This will be an array of loveliness * @todo: multiple servers * $servers = (isset($params['servers'])) ? $params['servers'] : array(); */ $server = array(); $server['host'] = $config->get('memcache_server_host', 'localhost'); $server['port'] = $config->get('memcache_server_port', 11211); // Create the memcache connection self::$_db = new Memcache(); self::$_db->addServer($server['host'], $server['port'], $this->_persistent); $memcachetest = @self::$_db->connect($server['host'], $server['port']); if ($memcachetest == false) { throw new RuntimeException('Could not connect to memcache server', 404); } // Memcahed has no list keys, we do our own accounting, initialise key index if (self::$_db->get($this->_hash . '-index') === false) { $empty = array(); self::$_db->set($this->_hash . '-index', $empty, $this->_compress, 0); } return; }
/** * Testing isSupported(). * * @return void */ public function testIsSupported() { if ($this->memcacheAvailable) { $this->assertThat($this->object->isSupported(), $this->isTrue(), 'Claims memcache is not loaded.'); } else { $this->markTestSkipped('This caching method is not supported on this system.'); } }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void */ protected function setUp() { if (!JCacheStorageMemcache::isSupported() || $this->isBlacklisted('memcache')) { $this->markTestSkipped('The Memcache cache handler is not supported on this system.'); } parent::setUp(); $this->handler = new JCacheStorageMemcache(); // Override the lifetime because the JCacheStorage API multiplies it by 60 (converts minutes to seconds) $this->handler->_lifetime = 2; }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. * * @return void */ protected function setUp() { if (!JCacheStorageMemcache::isSupported()) { $this->markTestSkipped('The Memcache cache handler is not supported on this system.'); } parent::setUp(); try { $this->handler = new JCacheStorageMemcache(); } catch (JCacheExceptionConnecting $e) { $this->markTestSkipped('Failed to connect to Memcache'); } // Override the lifetime because the JCacheStorage API multiplies it by 60 (converts minutes to seconds) $this->handler->_lifetime = 2; }
/** * return memcache connection object * * @static * @access private * @return object memcache connection object */ function &getConnection() { static $db = null; if (is_null($db)) { $params =& JCacheStorageMemcache::getConfig(); $persistent = isset($params['persistent']) ? $params['persistent'] : false; // This will be an array of loveliness $servers = isset($params['servers']) ? $params['servers'] : array(); // Create the memcache connection $db = new Memcache(); foreach ($servers as $server) { $db->addServer($server['host'], $server['port'], $persistent); } } return $db; }
/** * Check availability of all cache handlers * * @return void */ private function checkAvailability() { $this->available = array('apc' => JCacheStorageApc::isSupported(), 'apcu' => JCacheStorageApcu::isSupported(), 'cachelite' => JCacheStorageCachelite::isSupported(), 'file' => true, 'memcache' => JCacheStorageMemcache::isSupported(), 'memcached' => JCacheStorageMemcached::isSupported(), 'redis' => JCacheStorageRedis::isSupported(), 'wincache' => JCacheStorageWincache::isSupported(), 'xcache' => JCacheStorageXcache::isSupported()); }
/** * Testing isSupported(). * * @return void */ public function testIsSupported() { $this->assertEquals($this->extensionAvailable, $this->object->isSupported(), 'Claims Memcache is not loaded.'); }