Cachearium\Backend\CacheMemcached::singleton PHP Method

singleton() public static method

Cache constructor (this is a singleton).
public static singleton ( $servers = [] ) : Cache
return Cache The cache singleton.
    public static function singleton($servers = [])
    {
        static $instances;
        if (!isset($instances)) {
            $instances = new CacheMemcached();
            if (count($servers)) {
                $instances->addServers($servers);
            }
        }
        return $instances;
    }

Usage Example

 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);
     }
 }
All Usage Examples Of Cachearium\Backend\CacheMemcached::singleton