Cachearium\Backend\CacheFilesystem::singleton PHP Method

singleton() public static method

Cache constructor (this is a singleton).
public static singleton ( ) : CacheFS
return CacheFS The cache singleton.
    public static function singleton()
    {
        static $instances;
        if (!isset($instances)) {
            $instances = new CacheFilesystem();
        }
        return $instances;
    }

Usage Example

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