thiniphp tp5 使用缓存

在应用或者模块配置文件中配置好所用缓存的类型及相关参数:

如果是文件类型可以用

'cache'  => [
    'type'   => 'File',
    'path'   => CACHE_PATH,
    'prefix' => '',
    'expire' => 0,
],

如果是redis类型可以用

'cache' => [
        'type'   => 'Redis',
        'host'   => '127.0.0.1',
        'port'   => '6379',
        'password' => '',
        'timeout'=> 3600,
],

redis也可以用简化版,全部用系统的默认值

    'cache'  => [
        'type'   => 'Redis',
    ],

如果是缓存数据库查询的结果可以用

Db::name('table_name')->cache(true)->find();

一般情况下的使用方式是

use think\Cache;

    //查看缓存的数据结果
    public function getcache(){
        $data = Cache::get('name');
        echo($data);
    }

    //设置缓存的数据结果
    public function redistest(){
        Cache::set('name', 'wbj',3600);
    }

 

posted @ 2018-04-10 14:40  viof7852  阅读(283)  评论(0编辑  收藏  举报