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');
這樣就可以用緩存了