cache_dir = sys_get_temp_dir().'/caoym_temp'; }else{ $this->cache_dir = $cache_dir; } } /** * 设置key * @param string $key * @param mixed $var * @param int $ttl TODO: 暂不支持 * @return void */ public function set($key, $var, $ttl=0){ Verify::isTrue(is_dir($this->cache_dir) || @mkdir($this->cache_dir, 0777, true)); $path = $this->cache_dir.'/'.sha1($key); return SaftyFileWriter::write($path, serialize($var)); } /** * 删除key * @param string $key * @return boolean Returns true on success or false on failure. */ public function del($key){ $path = $this->cache_dir.'/'.sha1($key); return @unlink($path); } /** * 模拟apc, 只在没有apc的开发环境使用 * @param string $key * @param boolean $succeeded * @return mixed object on success or false on failure */ public function get($key, &$succeeded=null){ $succeeded = false; $path = $this->cache_dir.'/'.sha1($key); if(!file_exists($path)){ return false; } $res = file_get_contents($path); if($res === false){ return false; } $succeeded = true; return unserialize($res); } private $cache_dir; }