ThinkPHP5使用缓存

来源:互联网 发布:centos7 网络配置 编辑:程序博客网 时间:2024/06/17 17:39

1、在\application\config.php中设置如下:

'cache' =>  [    // 使用复合缓存类型    'type'  =>  'complex',    // 默认使用的缓存       'default'   =>  [        // 驱动方式        'type'   => 'File',      //!!在这设置换人的缓存方式        // 缓存保存目录        'path'   => CACHE_PATH,    ],    // 文件缓存    'file'   =>  [        // 驱动方式        'type'   => 'file',        // 设置不同的缓存保存目录        'path'   => RUNTIME_PATH . 'file/',    ],    // redis缓存    'redis'   =>  [        // 驱动方式        'type'   => 'redis',        // 服务器地址        'host'       => '127.0.0.1',    ],],

2、控制器中

use \think\Cache;

3、控制器中使用

Cache::set('name', 'tom',3600);Cache::get('name');

大笑这样就可以用缓存了