コード例 #1
0
ファイル: ZCache.php プロジェクト: kimthangatm/zcms
 /**
  * Returns a cached content
  *
  * @param string $keyName
  * @param int $lifetime
  * @return mixed
  */
 public function get($keyName, $lifetime = null)
 {
     if ($this->cache_status) {
         return $this->cache->get($keyName, $lifetime);
     } else {
         return null;
     }
 }
コード例 #2
0
ファイル: ApcCest.php プロジェクト: phalcon/cphalcon
 public function get(UnitTester $I)
 {
     $I->wantTo('Get data by using APC(u) as cache backend');
     $key = '_PHCA' . 'data-get';
     $data = [uniqid(), gethostname(), microtime(), get_include_path(), time()];
     $cache = new Apc(new Data(['lifetime' => 20]));
     $I->haveInApc($key, serialize($data));
     $I->assertEquals($data, $cache->get('data-get'));
     $I->assertNull($cache->get('non-existent-key'));
     $data = 'sure, nothing interesting';
     $I->haveInApc($key, serialize($data));
     $I->assertEquals($data, $cache->get('data-get'));
     $I->assertNull($cache->get('non-existent-key-2'));
 }
コード例 #3
0
ファイル: ModelTest.php プロジェクト: phalcon/cphalcon
 /**
  * Tests serializing model while using cache and keeping snapshots
  *
  * The snapshot should be saved while using cache
  *
  * @issue  12170, 12000
  * @author Wojciech Ślawski <*****@*****.**>
  * @since  2016-08-26
  */
 public function testSerializeSnapshotCache()
 {
     if (!extension_loaded('apc')) {
         $this->markTestSkipped('Warning: apc extension is not loaded');
     }
     if (!ini_get('apc.enabled') || PHP_SAPI === 'cli' && !ini_get('apc.enable_cli')) {
         $this->markTestSkipped('Warning: apc.enable_cli must be set to "On"');
     }
     if (extension_loaded('apcu') && version_compare(phpversion('apcu'), '5.1.6', '=')) {
         throw new \PHPUnit_Framework_SkippedTestError('Warning: APCu v5.1.6 was broken. See: https://github.com/krakjoe/apcu/issues/203');
     }
     $this->specify('Snapshot data should be saved while saving model to cache', function () {
         $cache = new Apc(new Data(['lifetime' => 20]));
         $robot = Robots::findFirst();
         expect($robot)->isInstanceOf(Robots::class);
         expect($robot->getSnapshotData())->notEmpty();
         $cache->save('robot', $robot);
         /** @var Robots $robot */
         $robot = $cache->get('robot');
         expect($robot)->isInstanceOf(Robots::class);
         expect($robot->getSnapshotData())->notEmpty();
         expect($robot->getSnapshotData())->equals($robot->toArray());
         $robot->text = 'abc';
         $cache->save('robot', $robot);
         /** @var Robots $robot */
         $robot = $cache->get('robot');
         expect($robot)->isInstanceOf(Robots::class);
         expect($robot->getSnapshotData())->notEmpty();
         expect($robot->getSnapshotData())->notEquals($robot->toArray());
     });
 }