Пример #1
0
 public function testDependencies()
 {
     $cache = Cachearium\Backend\CacheRAM::singleton();
     $ck1 = new CacheKey('recursion', 1, 'sub');
     $ck2 = new CacheKey('recursion', 2, 'sub');
     $ck3 = new CacheKey('recursion', 3, 'sub');
     $cd1 = new CacheData($ck1, 'this');
     $cd2 = new CacheData($ck2, 'is');
     $cd3 = new CacheData($ck3, 'recursion');
     $cd2->appendRecursionData($cd3);
     $cd1->appendRecursionData($cd2);
     $this->assertTrue($cache->storeData($cd3));
     $this->assertTrue($cache->storeData($cd2));
     $this->assertTrue($cache->storeData($cd1));
     $this->assertNotFalse($cache->getData($ck1));
     $this->assertNotFalse($cache->getData($ck2));
     $this->assertNotFalse($cache->getData($ck3));
     $this->assertEquals('thisisrecursion', $cd1->stringify($cache));
     $cd2 = new CacheData($ck2, 'breaks');
     $this->assertTrue($cache->storeData($cd2));
     try {
         $cache->getData($ck1);
         $this->fail();
     } catch (Cachearium\Exceptions\NotCachedException $e) {
         $this->assertTrue(true);
     }
 }
Пример #2
0
 /**
  * (non-PHPdoc)
  * @see \Cachearium\CacheAbstract::getData($k)
  */
 public function getData(CacheKey $k)
 {
     $cd = CacheData::unserialize($this->get($k));
     if ($cd->checkUpdateToDate($this)) {
         return $cd;
     }
     $this->delete($k);
     throw new NotCachedException();
 }
Пример #3
0
 private function dependency(CacheAbstract $cache)
 {
     // store
     $key1 = new CacheKey('Namespace', 'Subname');
     $cd = new CacheData($key1, 'xxxx');
     $depkey = new CacheKey('Namespace', 'SomeDep');
     $cd->addDependency($depkey);
     $cache->storeData($cd);
     // check if it is cached
     try {
         $data = $cache->getData($key1);
         $this->assertInstanceOf('Cachearium\\CacheData', $data);
         $this->assertEquals('xxxx', $data->getFirstData());
     } catch (Cachearium\Exceptions\NotCachedException $e) {
         $this->fail();
     }
     // invalidate a dependency
     $cache->invalidate($depkey);
     // get the original and it should be uncached
     try {
         $data = $cache->getData($key1);
         $this->fail();
     } catch (Cachearium\Exceptions\NotCachedException $e) {
         $this->assertTrue(true);
     }
 }
Пример #4
0
 private function dependencies(CacheAbstract $cache)
 {
     $this->assertFalse($cache->appendCallback('cacheCallback'));
     // not in loop
     $cache->recursivestart('parent', 1);
     echo 'parent start/';
     $this->assertFalse($cache->appendCallback('nawreanaweroi'));
     // invalid
     $cache->appendCallback('cacheCallback');
     $cache->recursivestart('child', 2);
     echo '|child first|';
     $cache->recursiveend(false);
     echo 'parent end/';
     $cache->recursiveend(false);
     $data = $cache->get('child', 2);
     $cachedata = CacheData::unserialize($data);
     $this->assertEquals('|child first|', $cachedata->stringify($cache));
     $data = $cache->get('parent', 1);
     $cachedata = CacheData::unserialize($data);
     $this->assertEquals('parent start/aaaa|child first|parent end/', $cachedata->stringify($cache));
     $cache->delete('child', 2);
     $cache->recursivestart('child', 2);
     echo '|child second|';
     $cache->recursiveend(false);
     $data = $cache->get('child', 2);
     $cachedata = CacheData::unserialize($data);
     $this->assertEquals('|child second|', $cachedata->stringify($cache));
     $data = $cache->get('parent', 1);
     $cachedata = CacheData::unserialize($data);
     $this->assertEquals('parent start/bbbb|child second|parent end/', $cachedata->stringify($cache));
 }