# Api开发---查询信息缓存Cache的应用 [TOC] 上节课 我们把一大堆东东通过最简单的方式列了出来 肯定有大佬们会说 你这查询效率能搞吗? 那这个章节就讲讲 TP5 一个非常牛逼的功能 查询缓存 ## 查询缓存的使用方法 详情当然看手册 在控制器中再复杂一个方法,在链式操作中加上 >[info] ->cache('AdminUser_'.$open_id,3600) 完成了 就这么简单 ~~~ <?php namespace app\base\model; use think\Model; class AdminUser extends Model { protected $table = "my_admin_user"; public function getInfoByOpenid($open_id){ return $this->where('weixin_openid',$open_id)->cache($this->table.'_'.$open_id,600)->find()->toArray(); } public function getDepartmentIdAttr($value,$data) { return $this->belongsTo('AdminDepartment')->where('id',$value)->value('name'); } public function getRoleIdAttr($value,$data){ //$ids = $this->belongsTo('AdminRole')->where('id',$value)->value('rule') ; return $ids = $this->belongsTo('AdminNode')->where('id','in',$this->belongsTo('AdminRole')->where('id',$value)->value('rule'))->cache('AdminNode_'.$value)->select(); } } ~~~ 这只是简单的缓存 后面 复杂的缓存信息和更新以后再讲