thinkphp缓存使用方法

Posted 我因代码而疯狂

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了thinkphp缓存使用方法相关的知识,希望对你有一定的参考价值。

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

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

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

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

//查询缓存,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);//缓存

以上是关于thinkphp缓存使用方法的主要内容,如果未能解决你的问题,请参考以下文章

thinkphp5的Redis缓存配置

thinkphp文件缓存怎么找到缓存文件

ThinkPHP使用Memcached缓存数据

ThinkPHP5配置redis缓存

thinkphp3.2局部不缓存的静态缓存

THINKPHP5获取设置缓存的例子