企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
### 缓存 ***** 如果要使用缓存功能,可以使用`\tian\Cache`类。 缓存数据文件位置在:runtime/cache/ **设置缓存**: ``` Cache::set("info", $info); ``` 上面 info 是缓存名称,$info 是数据源,数据源可以是字符串,数组,对象,Json等。 **获取缓存**: ``` Cache::get("info"); ``` **删除缓存**: ``` Cache::del("info"); ``` **验证缓存是否存在**: ``` Cache::has("info"); ``` has验证缓存是否存在,返回为 true 或 false **完整示例**: ``` <php namespace app\home\controller; use tian\Controller; use tian\Cache; use think\facade\Db; class Base extends Controller { public $lm; public function index() { //获取导航栏目 if (Cache::has("lm")==false) { $this->lm = $lm = Db::name('nav')->where('fid=0')->order('sort asc,id asc')->select()->toArray(); Cache::set("lm", $lm); }else{ $this->lm = Cache::get("lm"); } //数据赋值 $this->assign('lm',$this->lm); //模板渲染 $this->fetch('index'); } } ```