Example #1
0
 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));
 }
Example #2
0
 /**
  * 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);
     }
 }
Example #3
0
 public function prefixedQueryKeys(UnitTester $I)
 {
     $I->wantTo('Get prefixed cache keys by using APC(u) as cache backend');
     $prefix = 'app-data';
     $cache = new Apc(new Data(['lifetime' => 20]), ['prefix' => $prefix]);
     $key1 = '_PHCA' . 'app-data' . 'data-key-1';
     $key2 = '_PHCA' . 'app-data' . 'data-key-2';
     $key3 = '_PHCA' . 'data-key-3';
     $I->haveInApc([$key1 => 1, $key2 => 2, $key3 => 3], null);
     $keys = $cache->queryKeys($prefix);
     sort($keys);
     $I->assertEquals($keys, ['app-datadata-key-1', 'app-datadata-key-2']);
 }
Example #4
0
 /**
  * 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());
     });
 }