Home > PHP Framework > ThinkPHP > body text

What is thinkphp cache usage?

藏色散人
Release: 2022-12-08 09:36:21
Original
1171 people have browsed it

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);
Copy after login
        // 查询列表全部-----
        $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);//缓存
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!