public static final function run()
 {
     self::initCache();
     $repeats = self::getRepeats();
     $bar = new CliProgressBar($repeats);
     $key = md5('adfjkjkang');
     $data = range(0, 10);
     Cache::setAdapter(MemcacheAdapter::instance());
     Cache::set($key, $data);
     for ($i = 1; $i <= $repeats; ++$i) {
         Timer::start();
         Cache::get($key);
         Timer::stop();
         $bar->update($i);
     }
     self::addResult('Memcache', Timer::get());
     $bar = new CliProgressBar($repeats);
     Cache::setAdapter(MemcachedAdapter::instance());
     Timer::reset();
     for ($i = 1; $i <= $repeats; ++$i) {
         Timer::start();
         Cache::get($key);
         Timer::stop();
         $bar->update($i);
     }
     self::addResult('Memcached', Timer::get());
     Cache::clear();
 }
 public function run()
 {
     $this->initCache();
     $repeats = $this->getRepeats();
     $bar = new CliProgressBar($repeats);
     $data = range(0, 99);
     Cache::setAdapter(MemcacheAdapter::instance());
     for ($i = 1; $i <= $repeats; ++$i) {
         $key = sha1(uniqid());
         Timer::start();
         Cache::set($key, $data);
         Timer::stop();
         $bar->update($i);
     }
     $this->addResult('Memcache', Timer::get());
     $bar = new CliProgressBar($repeats);
     Timer::reset();
     Cache::setAdapter(MemcachedAdapter::instance());
     for ($i = 1; $i <= $repeats; ++$i) {
         $key = sha1(uniqid());
         Timer::start();
         Cache::set($key, $data);
         Timer::stop();
         $bar->update($i);
     }
     $this->addResult('Memcached', Timer::get());
     Cache::clear();
 }
 /**
  * Returns array that contains routes configuration
  *
  * @return array
  */
 public function getData()
 {
     if (false !== ($data = Cache::get($this->getPrefix()))) {
         return $data;
     }
     $data = $this->config->getData();
     Cache::set($this->getPrefix(), $data);
     return $data;
 }
 /**
  * @covers Veles\Cache\Adapters\MemcacheAdapter::delByTemplate
  */
 public function testDelByTemplate()
 {
     $key = uniqid('VELES::UNIT-TEST::DEL-BY-TPL::');
     $value = mt_rand(1, 1000);
     Cache::set($key, $value, 10);
     $result = $this->object->delByTemplate('VELES::UNIT-TEST::DEL-BY-TPL::');
     $msg = 'Memcache::delByTemplate() return wrong result!';
     $this->assertSame(true, $result, $msg);
     $result = $this->object->has($key);
     $msg = 'Key was not deleted by template!';
     $this->assertSame(false, $result, $msg);
     MemcacheRaw::setConnectionParams('localhost', 11213);
     $result = $this->object->delByTemplate('EnyKey');
     $msg = 'Wrong MemcacheAdapter::delByTemplate() behavior!';
     $this->assertSame(false, $result, $msg);
 }
Exemple #5
0
 /**
  * Save form security id to cache
  * @return bool
  */
 public function saveSid()
 {
     return Cache::set($this->name . $this->sid, true, 7200);
 }
 /**
  * @covers Veles\Cache\Adapters\MemcachedAdapter::decrement
  */
 public function testDecrement()
 {
     $key = uniqid('VELES::UNIT-TEST::');
     $value = mt_rand(1, 1000);
     Cache::set($key, $value, 10);
     $params = [[$key, null, --$value]];
     for ($i = 0; $i < 5; ++$i) {
         $key = uniqid('VELES::UNIT-TEST::');
         $value = mt_rand(1000, 2000);
         $offset = mt_rand(0, 1000);
         Cache::set($key, $value, 10);
         $params[] = [$key, $offset, $value - $offset];
     }
     foreach ($params as $param) {
         list($key, $offset, $expected) = $param;
         $result = null === $offset ? $this->object->decrement($key, 1) : $this->object->decrement($key, $offset);
         $msg = 'MemcachedAdapter::decrement returned wrong result type!';
         $this->assertInternalType('integer', $result, $msg);
         $msg = 'MemcachedAdapter::decrement returned wrong result value!';
         $this->assertSame($expected, $result, $msg);
     }
 }
 /**
  * @covers Veles\Cache\Adapters\MemcacheRaw::query
  */
 public function testQuery()
 {
     $key = uniqid("VELES::UNIT-TEST::");
     $value = mt_rand(0, 1000);
     Cache::set($key, $value, 100);
     $object = new MemcacheRaw();
     $output = $object->query("get {$key}");
     $expr = "/^VALUE {$key} [\\d\\s]+{$value}\\s\$/";
     $result = preg_match($expr, $output);
     $msg = 'MemcacheRaw::query return wrong result!';
     $this->assertSame(1, $result, $msg);
 }