예제 #1
0
 public function testExpire()
 {
     $key = uniqid();
     $c = new MemoryCache();
     $this->assertTrue($c->set($key, ['bar' => ['baz']], 1));
     $this->assertEquals(['bar' => ['baz']], $c->get($key));
     $this->assertTrue($c->expires($key) <= time() + 1);
     sleep(2);
     $this->assertNull($c->get($key));
     $this->assertEquals(0, $c->expires('foobar'));
 }
예제 #2
0
 function &cachedExecute($arr = null, $timeout = 30)
 {
     if (function_exists('hash')) {
         $hash = 'sqlc' . hash('sha1', $this->queryString . serialize($arr));
     } else {
         $hash = 'sqlc' . sha1($this->queryString . serialize($arr));
     }
     if (MemoryCache::find($hash)) {
         return MemoryCache::get($hash);
     }
     $this->execute($arr);
     if (!$this->rowCount()) {
         $rows = array();
     } else {
         $rows = $this->fetchAll();
     }
     MemoryCache::put($hash, $rows, $timeout);
     return $rows;
 }
예제 #3
0
 /**
  * 缓存路由表
  */
 private static function getCacheRoute()
 {
     $urlArr = parse_url($_SERVER['REQUEST_URI']);
     $urlArr['path'] = trim($urlArr['path'], '\\/');
     if (empty($urlArr['path'])) {
         $urlArr['path'] = 'index';
     }
     $memCacheObj = new MemoryCache();
     $urlRes = @$memCacheObj->get($urlArr['path']);
     return $urlRes;
 }
예제 #4
0
파일: FileCache.php 프로젝트: 0x20h/phloppy
 /**
  * Retrieve the nodes under the given key.
  *
  * @param string $key
  *
  * @return string[]
  */
 public function get($key)
 {
     $this->read();
     return parent::get($key);
 }
예제 #5
0
 public static function &get($id)
 {
     if (MemoryCache::find($id)) {
         return MemoryCache::get($id);
     }
     if (DiskCache::find($id)) {
         return DiskCache::get($id);
     }
     return null;
 }