配置方式如下:
1'cache' => [ 2 // 使用复合缓存类型 3 'type' => 'complex', 4 // 默认使用的缓存 5 'default' => [ 6 // 驱动方式 7 'type' => 'File', 8 // 缓存保存目录 9 'path' => CACHE_PATH, 10 ], 11 // 文件缓存 12 'file' => [ 13 // 驱动方式 14 'type' => 'file', 15 // 设置不同的缓存保存目录 16 'path' => RUNTIME_PATH . 'file/', 17 ], 18 // redis缓存 19 'redis' => [ 20 // 驱动方式 21 'type' => 'redis', 22 // 服务器地址 23 'host' => '192.168.1.100', 24 ], 25 ],
使用符合缓存类型时,需要根据需要使用store方法切换缓存。
当使用
1Cache::set('name', 'value'); 2Cache::get('name');
的时候,使用的是default缓存标识的缓存配置。如果需要切换到其它的缓存标识操作,可以使用:
1// 切换到file操作 2Cache::store('file')->set('name','value'); 3Cache::get('name'); 4// 切换到redis操作 5Cache::store('redis')->set('name','value'); 6Cache::get('name');