示例#1
0
 function testStoreFetch()
 {
     $key = 'storekey2' . time();
     $store = HandsetDetection\HDStore::getInstance();
     $store->store($key, $this->testData);
     $cache = new HandsetDetection\HDCache();
     $data = $cache->read($key);
     $this->assertEquals(false, $data);
     $data = $store->fetch($key);
     $this->assertEquals($this->testData, $data);
     $exists = is_file($store->directory . DIRECTORY_SEPARATOR . "{$key}.json");
     $this->assertTrue($exists);
 }
示例#2
0
 function testVolume()
 {
     $cache = new HandsetDetection\HDCache();
     $keys = array();
     $now = time();
     for ($i = 0; $i < 10000; $i++) {
         $key = 'test' . $now . $i;
         $cache->write($key, $this->testData);
     }
     for ($i = 0; $i < 10000; $i++) {
         $key = 'test' . $now . $i;
         $reply = $cache->read($key);
         $this->assertEquals($this->testData, $reply);
     }
 }
示例#3
0
 function testVolume()
 {
     $testDir = "/tmp/testdir";
     if (!is_dir($testDir)) {
         mkdir($testDir);
     }
     $config = array('cache' => array('file' => array('directory' => $testDir)));
     $cache = new HandsetDetection\HDCache($config);
     $now = time();
     for ($i = 0; $i < $this->volumeTest; $i++) {
         $key = 'test' . $now . $i;
         // Write
         $reply = $cache->write($key, $this->testData);
         $this->assertTrue($reply);
         // Read
         $reply = $cache->read($key);
         $this->assertEquals($this->testData, $reply);
         // Delete
         $reply = $cache->delete($key);
         $this->assertTrue($reply);
         // Read
         $reply = $cache->read($key);
         $this->assertNull($reply);
     }
     $end = time();
     $cache->purge();
 }
 function testVolume()
 {
     $cache = new HandsetDetection\HDCache();
     $now = time();
     for ($i = 0; $i < $this->volumeTest; $i++) {
         $key = 'test' . $now . $i;
         // Write
         $reply = $cache->write($key, $this->testData);
         $this->assertTrue($reply);
         // Read
         $reply = $cache->read($key);
         $this->assertEquals($this->testData, $reply);
         // Delete
         $reply = $cache->delete($key);
         $this->assertTrue($reply);
         // Read
         $reply = $cache->read($key);
         $this->assertNull($reply);
     }
     $end = time();
     $cache->purge();
 }
 function testPoolVolume()
 {
     $config = array('cache' => array('memcached' => array('pool' => 'mypool', 'options' => '', 'servers' => array(array('localhost', '11211')))));
     $cache = new HandsetDetection\HDCache($config);
     $now = time();
     for ($i = 0; $i < $this->volumeTest; $i++) {
         $key = 'test' . $now . $i;
         // Write
         $reply = $cache->write($key, $this->testData);
         $this->assertTrue($reply);
         // Read
         $reply = $cache->read($key);
         $this->assertEquals($this->testData, $reply);
         // Delete
         $reply = $cache->delete($key);
         $this->assertTrue($reply);
         // Read
         $reply = $cache->read($key);
         $this->assertNull($reply);
     }
     $end = time();
     $cache->purge();
 }
示例#6
0
 function testVolume()
 {
     $config = array('cache' => array('none' => true));
     $cache = new HandsetDetection\HDCache($config);
     $now = time();
     for ($i = 0; $i < $this->volumeTest; $i++) {
         $key = 'test' . $now . $i;
         // Write
         $reply = $cache->write($key, $this->testData);
         $this->assertFalse($reply);
         // Read
         $reply = $cache->read($key);
         $this->assertFalse($reply);
         // Delete
         $reply = $cache->delete($key);
         $this->assertFalse($reply);
         // Read
         $reply = $cache->read($key);
         $this->assertFalse($reply);
     }
     $end = time();
     $cache->purge();
 }
示例#7
0
 function testGetName()
 {
     $config = array('cache' => array('memcached' => array('pool' => 'mypool', 'options' => '', 'servers' => array(array('localhost', '11211')))));
     $cache = new HandsetDetection\HDCache($config);
     $this->assertEquals('memcached', $cache->getName());
 }
示例#8
0
 function testGetName()
 {
     $config = array('cache' => array('apc' => true));
     $cache = new HandsetDetection\HDCache($config);
     $this->assertEquals('apc', $cache->getName());
 }
示例#9
0
 function testGetName()
 {
     $cache = new HandsetDetection\HDCache();
     $cacheNames = array('apc', 'apcu', 'memcache', 'memcached', 'file', 'none');
     $this->assertContains($cache->getName(), $cacheNames);
 }