setDriver() public method

public setDriver ( Stash\Interfaces\DriverInterface $driver )
$driver Stash\Interfaces\DriverInterface
Exemplo n.º 1
0
 protected function setUp()
 {
     $this->driver = new Ephemeral([]);
     $this->pool = new Pool();
     $this->pool->setDriver($this->driver);
     $this->pool->setItemClass('Bankiru\\Stash\\TaggedItem');
 }
Exemplo n.º 2
0
 /**
  * Производит конфигурирование кэшера
  *
  * @param array $config Опции конфигурации
  */
 private function configureCacher(array $config = [])
 {
     if (!array_key_exists('cacher', $config)) {
         return;
     }
     $cacherConfig = $config['cacher'];
     if (is_object($cacherConfig)) {
         $this->cacher = $cacherConfig;
     }
     if (is_array($cacherConfig)) {
         if (array_key_exists('drivers', $cacherConfig)) {
             $drivers = [];
             foreach ($cacherConfig['drivers'] as $driverConfig) {
                 /** @var DriverInterface $driver */
                 $driver = new $driverConfig['class']();
                 if (array_key_exists('options', $driverConfig)) {
                     $driver->setOptions($driverConfig['options']);
                 }
                 $drivers[] = $driver;
             }
             $driver = new Composite();
             $driver->setOptions(['drivers' => $drivers]);
             $this->cacher->setDriver($driver);
         }
         if (array_key_exists('expires', $cacherConfig) && is_array($cacherConfig['expires'])) {
             $this->cacherExpires = $cacherConfig['expires'];
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Disables the cache
  */
 public function disable()
 {
     // save the current driver if not yet black hole so it can be restored on enable()
     if (!$this->pool->getDriver() instanceof BlackHole) {
         $this->driver = $this->pool->getDriver();
     }
     $this->pool->setDriver(new BlackHole());
     $this->enabled = false;
 }
Exemplo n.º 4
0
 public function testConstruction()
 {
     $key = array('apple', 'sauce');
     $driver = new Sqlite(array());
     $pool = new Pool();
     $pool->setDriver($driver);
     $item = $pool->getItem('testKey');
     $item->set($key);
     $this->assertTrue($pool->save($item), 'Able to load and store with unconfigured extension.');
 }
Exemplo n.º 5
0
 public function testPoolClear()
 {
     $pool = new Pool();
     $pool->setDriver(new DriverExceptionStub());
     $item = $pool->getItem('test');
     $this->assertFalse($item->isDisabled());
     $this->assertFalse($pool->clear());
     $item = $pool->getItem('test');
     $this->assertTrue($item->isDisabled(), 'Is disabled after exception is thrown in driver');
     $this->assertFalse($pool->clear());
 }
 protected function setUp()
 {
     $this->redis = new Redis();
     $cachePool = new Pool();
     $cachePool->setDriver($this->redis);
     $this->repository = new RepositoryCache($cachePool, new InMemoryRepository(), rand(PHP_INT_MIN, PHP_INT_MAX), self::TTL_IN_SECONDS);
     $this->repository->add(new Customer(1, 'John Doe', 3, 25.125, new DateTime('2014-12-11')));
     $this->repository->add(new Customer(2, 'Junichi Masuda', 3, 50978.125, new DateTime('2013-02-22')));
     $this->repository->add(new Customer(3, 'Shigeru Miyamoto', 5, 47889850.125, new DateTime('2010-12-01')));
     $this->repository->add(new Customer(4, 'Ken Sugimori', 4, 69158.68700000001, new DateTime('2010-12-10')));
 }
Exemplo n.º 7
0
 function setup_cache_mocks(Pool $cache)
 {
     $cache->setDriver(Argument::any())->willReturn(true);
     $item = $this->prophet->prophesize('Stash\\Item');
     $item->get()->willReturn('data');
     $item->set(Argument::cetera())->willReturn(true);
     $item->isMiss()->willReturn(true);
     $item->lock()->willReturn(true);
     $item->clear()->willReturn(true);
     $item = $item->reveal();
     $cache->getItem(Argument::any())->willReturn($item);
     $cache->purge()->willReturn(true);
     $cache->flush()->willReturn(true);
     return ['cache' => $cache];
 }