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')); }
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; }
/** * 缓存路由表 */ 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; }
/** * Retrieve the nodes under the given key. * * @param string $key * * @return string[] */ public function get($key) { $this->read(); return parent::get($key); }
public static function &get($id) { if (MemoryCache::find($id)) { return MemoryCache::get($id); } if (DiskCache::find($id)) { return DiskCache::get($id); } return null; }