コード例 #1
0
ファイル: ApcCest.php プロジェクト: mattvb91/cphalcon
 public function decrement(UnitTester $I)
 {
     $I->wantTo('Decrement counter by using APC as cache backend');
     $key = '_PHCA' . 'decrement';
     $cache = new Apc(new Data(['lifetime' => 20]));
     apc_store($key, 100);
     $I->assertEquals(99, $cache->decrement('decrement'));
     $I->assertEquals(99, apc_fetch($key));
     $I->assertEquals(96, $cache->decrement('decrement', 3));
     $I->assertEquals(96, apc_fetch($key));
     $I->assertEquals(90, $cache->decrement('decrement', 6));
     $I->assertEquals(90, apc_fetch($key));
     $key = '_PHCA' . 'decrement-2';
     $cache->save('decrement-2', 90);
     $I->assertEquals(90, apc_fetch($key));
     $I->assertEquals(89, $cache->decrement('decrement-2'));
     $I->assertEquals(89, apc_fetch($key));
     $I->assertEquals(78, $cache->decrement('decrement-2', 11));
     $I->assertEquals(78, apc_fetch($key));
     $I->assertEquals(8, $cache->decrement('decrement-2', 70));
     $I->assertEquals(8, apc_fetch($key));
 }
コード例 #2
0
ファイル: ZCache.php プロジェクト: kimthangatm/zcms
 /**
  * Stores cached content
  *
  * @param string $keyName
  * @param string $content
  * @param int $lifetime
  * @param boolean $stopBuffer
  */
 public function set($keyName = null, $content = null, $lifetime = null, $stopBuffer = null)
 {
     if ($this->cache_status) {
         $this->cache->save($keyName, $content, $lifetime, $stopBuffer);
     }
 }
コード例 #3
0
ファイル: ApcCest.php プロジェクト: phalcon/cphalcon
 public function save(UnitTester $I)
 {
     $I->wantTo('Save data by using APC(u) as cache backend');
     $key = '_PHCA' . 'data-save';
     $data = [uniqid(), gethostname(), microtime(), get_include_path(), time()];
     $cache = new Apc(new Data(['lifetime' => 20]));
     $I->dontSeeInApc($key);
     $cache->save('data-save', $data);
     $I->seeInApc($key, serialize($data));
     $data = 'sure, nothing interesting';
     $I->dontSeeInApc('non-existent-key', serialize($data));
     $cache->save('data-save', $data);
     $I->seeInApc($key, serialize($data));
 }
コード例 #4
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());
     });
 }