/** * Cache constructor (this is a singleton). * * @param $serves optional. If present, addServers() is called with this parameter * but only if the singleton is being created for the first time. * @return Cache The cache singleton. * @codeCoverageIgnore */ public static function singleton($servers = []) { static $instances; if (!isset($instances)) { $instances = new CacheMemcached(); if (count($servers)) { $instances->addServers($servers); } } return $instances; }
public function testNamespace() { $cache = CacheMemcached::singleton(); $this->assertEquals($cache, $cache->setNamespace("testmem")); $this->assertEquals("testmem", $cache->getNamespace()); $key = new CacheKey('namespace', 1); $cache->store(333, $key); try { $data = $cache->get($key); } catch (Cachearium\Exceptions\NotCachedException $e) { $this->fail(); } $this->assertEquals($cache, $cache->setNamespace("other")); try { $data = $cache->get($key); $this->fail(); } catch (Cachearium\Exceptions\NotCachedException $e) { $this->assertTrue(true); } }
public function testClearAll() { $cacheKey = new CacheKey('test', 1); $cacheData = new CacheData($cacheKey, 'test'); $caches = [CacheRAM::singleton(), CacheFilesystem::singleton()]; if (CacheMemcached::hasMemcachedExt()) { $caches[] = CacheMemcached::singleton(); } foreach ($caches as $cacheInst) { $cacheInst->enable()->storeData($cacheData); $retrievedData = $cacheInst->getData($cacheKey); $this->assertEquals($cacheData->getFirstData(), $retrievedData->getFirstData()); } CacheAbstract::clearAll(); foreach ($caches as $cacheInst) { try { $retrievedData = $cacheInst->getData($cacheKey); $this->fail('Cache should be empty after a clearAll call !'); } catch (\Cachearium\Exceptions\NotCachedException $e) { $this->assertTrue(true, 'All cache was cleaned'); } } }
/** * Clears all cache classes. * @codeCoverageIgnore */ public static function clearAll() { $caches = [\Cachearium\Backend\CacheRAM::singleton(), \Cachearium\Backend\CacheFilesystem::singleton(), \Cachearium\Backend\CacheMemcached::singleton()]; foreach ($caches as $cacheInst) { if ($cacheInst->isEnabled()) { $cacheInst->clear(); } } }
public function teststartCallbackMemcached() { $cache = CacheMemcached::singleton(); if ($cache->isEnabled()) { $this->_startcallback($cache); } }
public function testClash() { $cache = CacheMemcached::singleton([['localhost', 11211]]); try { ob_start(); if (!$cache->startP('testClash', 0)) { if (!$cache->startP('testClash', 0)) { $cache->end(); } $cache->end(); } $this->assertFalse(true); } catch (Cachearium\Exceptions\CacheKeyClashException $e) { $this->assertTrue(true); } }