LEFTJOIN('suit_explain e','l.suit_two=e.name_two')"; 2 , just cache via "Cache::store('redis')->set('list',$adata);"."/> LEFTJOIN('suit_explain e','l.suit_two=e.name_two')"; 2 , just cache via "Cache::store('redis')->set('list',$adata);".">

Home >PHP Framework >ThinkPHP >What is thinkphp cache usage?

What is thinkphp cache usage?

藏色散人
藏色散人Original
2022-12-08 09:36:211208browse

Thinkphp cache usage: 1. Use model query, with code statements such as "$data = SlsjList::alias('l') ->LEFTJOIN('suit_explain e','l.suit_two=e .name_two')"; 2. Cache via "Cache::store('redis')->set('list',$adata);".

What is thinkphp cache usage?

The operating environment of this tutorial: Windows 7 system, ThinkPHP version 5, Dell G3 computer.

thinkphp What is caching usage?

thinkphp cache usage method

The first code is our normal query method

The second one is in our own Create the method under the cache controller

The cache must be run for storage before it can be queried

Because the array is stored, the array must be encoded and decoded

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

Recommended learning: "thinkPHP Video Tutorial"

The above is the detailed content of What is thinkphp cache usage?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn