예제 #1
0
 public function enable()
 {
     if (!extension_loaded('apc')) {
         $this->enabled = false;
         return false;
     }
     return parent::enable();
 }
예제 #2
0
 private function _startNested(CacheAbstract $cache)
 {
     $expected = ["first level", "second level 1", "second level 2", "second level 3"];
     $i = 0;
     $data = '';
     if (!($data = $cache->start(new CacheKey('startnested', 'first', 0), null, false))) {
         $this->assertTrue(true);
         echo $expected[$i++];
         if (!$cache->start(new CacheKey('startnested', 'second', $i), null, false)) {
             echo $expected[$i++];
             if (!$cache->start(new CacheKey('startnested', 'second', $i), null, false)) {
                 echo $expected[$i++];
                 if (!$cache->start(new CacheKey('startnested', 'second', $i), null, false)) {
                     echo $expected[$i++];
                     $cache->end();
                 }
                 $cache->end();
             }
             $cache->end();
         }
         $data = $cache->end(false);
     } else {
         $this->assertTrue(false);
     }
     $this->assertEquals(implode('', $expected), $data);
 }
예제 #3
0
 protected function _startcallback(CacheAbstract $cache)
 {
     $key = new CacheKey("startcallback", 1);
     $cache->clean($key);
     $this->assertFalse($cache->start($key));
     echo "something ";
     $this->assertTrue($cache->appendCallback('callbackTesterStart'));
     echo " otherthing";
     $output = $cache->end(false);
     $this->assertContains(CALLBACKVALUE, $output);
     // run again, we should have another value
     $second = $cache->start($key, null, false);
     $this->assertNotFalse($second);
     $this->assertContains(CALLBACKVALUE, $second);
     $this->assertNotEquals($second, $output);
 }
예제 #4
0
 public function testCacheNull()
 {
     $key = new CacheKey('any', 'thing');
     $cache = CacheNull::singleton();
     $this->assertInstanceOf('Cachearium\\Backend\\CacheNull', $cache);
     $cache = CacheAbstract::factory('Null');
     $this->assertInstanceOf('Cachearium\\Backend\\CacheNull', $cache);
     try {
         $cache->get($key);
         $this->assertTrue(false);
     } catch (Cachearium\Exceptions\NotCachedException $e) {
         $this->assertTrue(true);
     }
     $this->assertEquals(5, $cache->increment(1, $key, 5));
     $this->assertTrue($cache->store(10, $key));
     $this->assertTrue($cache->delete($key));
     $this->assertTrue($cache->clean($key));
     $this->assertTrue($cache->clear());
     $this->assertFalse($cache->start($key));
     $cache->end();
     $cache->prefetch(array());
     $cache->enable(true);
 }
예제 #5
0
 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');
         }
     }
 }
예제 #6
0
 /**
  * (non-PHPdoc)
  * @see \Cachearium\CacheAbstract::setDefaultLifetime($lifetime)
  */
 public function setDefaultLifetime($lifetime = 0)
 {
     parent::setDefaultLifetime($lifetime);
     $this->cache->setLifeTime($this->getDefaultLifetime());
 }
예제 #7
0
 public function _dependencies(CacheAbstract $cache)
 {
     $cache->start('parent', 1);
     $cache->addDependency();
     echo 'parent start/';
     $this->assertFalse($cache->appendCallback('nawreanaweroi'));
     // invalid
     $cache->appendCallback('cacheCallback');
     $cache->start('child', 2);
     echo '|child first|';
     $cache->end(false);
     echo 'parent end/';
     $cache->end(false);
 }
예제 #8
0
 public static function setUpBeforeClass()
 {
     CacheAbstract::clearAll();
 }