使用缓存
public function pageQuery(){
$rs = cache('role');
if(!$rs){
$key = input('key');
$where[] = ['status','=',1];
if($key != '')$where[] = ['roleTitle','like','%'.$key.'%'];
$rs = $this->where($where)->field('roleId,roleTitle,roleDesc')->order('roleId', 'desc')->paginate();
}
cache('role',$rs,86400);
return $rs;
}
如果缓存存在,就不会在去数据库调取了。runtime/cache里面会生成文件

清除缓存
/**
* 清除缓存
*/
public function clearCache(){
\think\facade\Cache::clear();
return ZHTReturn('清除成功',1);
}
1小时=60*60=3600秒
1天=24*60*60=86400秒
1周=7*24*60*60=604800秒
1月=30*24*60*60=2592000秒
1年=365*24*60*60=31536000秒
|