thinkphp缓存使用方法
2022-07-28 14:14:58
175
{{single.collect_count}}

第一个代码是我们正常情况下查询的方法

第二个是在我们自己创建得到缓存控制器下的方法

必须运行缓存进行储存,才可以被查询到

因为储存的是数组,所以必须对数组进行编码和解码

//查询缓存,list是缓存时的名字$list = Cache::store('redis')->get('list');$list = json_decode($list);//解码foreach($list as $key){//for循环$key = (array)$key;//对象转数组$data[] =$key;}return json($data);
// 查询列表全部-----$data = SlsjList::alias('l')//用的是模型查询->LEFTJOIN('suit_explain e','l.suit_two=e.name_two')->select();//数据库多表查询$data = $data->toArray();//调用toArray方法转数组$adata = json_encode($data);//编码// 缓存列表Cache::store('redis')->set('list',$adata);//缓存

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}