thinkphp5 mysql缓存_thinkphp5.1中使用缓存和清除缓存

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:56   1416   0

使用缓存

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里面会生成文件

0fa6d1ef0d3ce4ad98aa337058638b12.png

清除缓存

/**

* 清除缓存

*/

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秒

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP