Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
 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();
 }
 /**
  * @covers Veles\Cache\Adapters\CacheAdapterAbstract::instance
  * @covers Veles\Cache\Adapters\CacheAdapterAbstract::invokeLazyCalls
  */
 public function testInstance()
 {
     $expected = __NAMESPACE__ . '\\CacheAdapterAbstractChild';
     CacheAdapterAbstractChild::setInstance(null);
     CacheAdapterAbstractChild::addCalls([]);
     $result = CacheAdapterAbstractChild::instance();
     $msg = 'Adapter returned wrong instance object!';
     $this->assertInstanceOf($expected, $result, $msg);
     CacheAdapterAbstractChild::setInstance(null);
     CacheAdapterAbstractChild::addCalls([['method' => 'testCall', 'arguments' => ['string']]]);
     $result = CacheAdapterAbstractChild::instance();
     $msg = 'Adapter returned wrong instance object!';
     $this->assertInstanceOf($expected, $result, $msg);
     $result = CacheAdapterAbstractChild::getCalls();
     $this->assertSame([], $result);
     Cache::setAdapter(MemcachedAdapter::instance());
 }
 * @license   The BSD 3-Clause License
 *            <https://tldrlegal.com/license/bsd-3-clause-license-(revised)>
 */
namespace Veles\Tests;

use Veles\AutoLoader;
use Veles\Cache\Adapters\MemcacheAdapter;
use Veles\Cache\Adapters\MemcachedAdapter;
use Veles\Cache\Adapters\MemcacheRaw;
use Veles\Cache\Cache;
use Veles\View\Adapters\NativeAdapter;
use Veles\View\View;
//ini_set('error_reporting', E_ALL);
//ini_set('display_errors', '1');
//ini_set('display_startup_errors', '1');
define('LIB_DIR', realpath(__DIR__ . '/../..'));
define('TEST_DIR', realpath(LIB_DIR . '/Veles/Tests'));
date_default_timezone_set('Europe/Moscow');
require LIB_DIR . '/Veles/AutoLoader.php';
$includes = LIB_DIR . ':' . TEST_DIR . ':' . realpath(__DIR__ . '/Project');
set_include_path(implode(PATH_SEPARATOR, [$includes, get_include_path()]));
AutoLoader::init();
$view_adapter = new NativeAdapter();
$view_adapter->setTemplateDir(TEST_DIR . '/Project/View/');
View::setAdapter($view_adapter);
// Cache initialization
MemcacheRaw::setConnectionParams('localhost', 11211);
MemcachedAdapter::addCall('addServer', ['localhost', 11211]);
MemcacheAdapter::addCall('addServer', ['localhost', 11211]);
Cache::setAdapter(MemcachedAdapter::instance());
 public static function tearDownAfterClass()
 {
     Cache::setAdapter(MemcachedAdapter::instance());
     MemcacheRaw::setConnectionParams('localhost', 11211);
 }
Exemplo n.º 6
0
 /**
  * @covers Veles\Cache\Cache::delByTemplate
  * @depends testSet
  */
 public function testDelByTemplate()
 {
     Cache::setAdapter(MemcachedAdapter::instance());
     $key = uniqid('VELES::UNIT-TEST::DEL-BY-TPL::');
     $value = uniqid();
     Cache::set($key, $value, 10);
     $result = Cache::delByTemplate('VELES::UNIT-TEST::DEL-BY-TPL::');
     $msg = 'Cache::delByTemplate return wrong result!';
     $this->assertSame(true, $result, $msg);
     $result = Cache::has($key);
     $msg = 'Key was not deleted by template!';
     $this->assertSame(false, $result, $msg);
 }
 /**
  * Cache adapter can be reset in other tests
  */
 public static function setUpBeforeClass()
 {
     Cache::setAdapter(MemcachedAdapter::instance());
 }