
但实际上如果你在设置缓存的时候直接这么写:
cache('test',['a'=>123]);最终你会发现,这个缓存有效期是永久的,看源码后发现(/thinkphp/helper.php,375行)cache函数下面有这样的代码:// 缓存数据
if (is_array($options)) {
$expire = isset($options['expire']) ? $options['expire'] : null; //修复查询缓存无法设置过期时间
} else {
$expire = is_numeric($options) ? $options : null; //默认快捷缓存设置过期时间
}就是说,到了这一步如果$options为null或者空,$expire是设置为null的;再看看缓存驱动文件(/thinkphp/cache/driver/File.php)的set函数:

$this->options['expire']的值默认是0的,所以整个运行下来,居然没有发现载入配置的地方,可能是我没有看完,但我还是直接写了自己的自定义方法,手动加载配置文件
function safeCache($name, $value = '', $options = null, $tag = null){
if (is_null($options)){
$options = config('cache'); //引入配置参数(修正由于框架里面没有对有效时间设置)
}
return cache($name, $value, $options, $tag);
} 最佳答案