set() public method

public set ( $value )
 public function testConstructionOptions()
 {
     $key = array('apple', 'sauce');
     $options = array();
     $options['servers'][] = array('127.0.0.1', '11211', '50');
     $options['servers'][] = array('127.0.0.1', '11211');
     $options['extension'] = $this->extension;
     $driver = new Memcache();
     $driver->setOptions($options);
     $item = new Item();
     $poolStub = new PoolGetDriverStub();
     $poolStub->setDriver($driver);
     $item->setPool($poolStub);
     $item->setKey($key);
     $this->assertTrue($item->set($key), 'Able to load and store memcache driver using multiple servers');
     $options = array();
     $options['extension'] = $this->extension;
     $driver = new Memcache();
     $driver->setOptions($options);
     $item = new Item();
     $poolStub = new PoolGetDriverStub();
     $poolStub->setDriver($driver);
     $item->setPool($poolStub);
     $item->setKey($key);
     $this->assertTrue($item->set($key), 'Able to load and store memcache driver using default server');
 }
Example #2
0
 public function testSet()
 {
     $item = new Item();
     $poolStub = new PoolGetDriverStub();
     $poolStub->setDriver(new DriverExceptionStub());
     $item->setPool($poolStub);
     $item->setKey(array('path', 'to', 'store'));
     $this->assertFalse($item->isDisabled());
     $this->assertFalse($item->set(array(1, 2, 3), 3600)->save());
     $this->assertTrue($item->isDisabled(), 'Is disabled after exception is thrown in driver');
 }
Example #3
0
 public function testConstruction()
 {
     $key = array('apple', 'sauce');
     $options = array();
     $driver = new Sqlite();
     $driver->setOptions($options);
     $item = new Item();
     $poolSub = new PoolGetDriverStub();
     $poolSub->setDriver($driver);
     $item->setPool($poolSub);
     $item->setKey($key);
     $this->assertTrue($item->set($key), 'Able to load and store with unconfigured extension.');
 }
Example #4
0
 public function testConstruction()
 {
     $key = array('apple', 'sauce');
     $options = array();
     $options['servers'][] = array('127.0.0.1', '11211', '50');
     $driver = new Memcache($options);
     $item = new Item();
     $poolStub = new PoolGetDriverStub();
     $poolStub->setDriver($driver);
     $item->setPool($poolStub);
     $item->setKey($key);
     $this->assertTrue($item->set($key)->save(), 'Able to load and store with unconfigured extension.');
 }
Example #5
0
 public function testKeyCollisions2()
 {
     $driver = new $this->driverClass();
     $poolStub = new PoolGetDriverStub();
     $poolStub->setDriver($driver);
     $item1 = new Item();
     $item1->setPool($poolStub);
     $item1->setKey(array('#'));
     $item1->set('X');
     $item2 = new Item();
     $item2->setPool($poolStub);
     $item2->setKey(array(':'));
     $item2->set('Y');
     $this->assertEquals('X', $item1->get());
 }
 /**
  * Test that the paths are created using the key hash function.
  */
 public function testOptionKeyHashFunctionDirs()
 {
     $hashfunctions = array('Stash\\Test\\Driver\\strdup', 'strrev', 'md5', function ($value) {
         return abs(crc32($value));
     });
     $paths = array('one', 'two', 'three', 'four');
     foreach ($hashfunctions as $hashfunction) {
         $driver = new FileSystem();
         $driver->setOptions(array('keyHashFunction' => $hashfunction, 'path' => sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'stash', 'dirSplit' => 1));
         $rand = str_repeat(uniqid(), 32);
         $item = new Item();
         $poolStub = new PoolGetDriverStub();
         $poolStub->setDriver($driver);
         $item->setPool($poolStub);
         $item->setKey($paths);
         $item->set($rand);
         $allpaths = array_merge(array('cache'), $paths);
         $predicted = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'stash' . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, array_map($hashfunction, $allpaths)) . '.php';
         $this->assertFileExists($predicted);
     }
 }
 private function assertDisabledStash(Item $stash)
 {
     $this->assertFalse($stash->set('true'), 'storeData returns false for disabled cache');
     $this->assertNull($stash->get(), 'getData returns null for disabled cache');
     $this->assertFalse($stash->clear(), 'clear returns false for disabled cache');
     $this->assertTrue($stash->isMiss(), 'isMiss returns true for disabled cache');
     $this->assertFalse($stash->extendCache(), 'extendCache returns false for disabled cache');
     $this->assertTrue($stash->lock(100), 'lock returns true for disabled cache');
 }