我有这段代码,我认为会永远记住缓存:
$setting = \Cache::remember('website_description', 0, function() {
return App\Models\Setting::where('name', 'website_description')->first();
});
但它根本不记得,有人告诉我,通过0
来记住功能会让它永远记住。由于这不起作用,我可以将项目永远放在缓存中吗?
答案 0 :(得分:18)
只需将remember
更改为rememberForever
并删除时间参数
$setting = \Cache::rememberForever('website_description', function() {
return App\Models\Setting::where('name', 'website_description')->first();
});
答案 1 :(得分:2)
你可以试试这个:
if (! \Cache::has('website_description')) {
\Cache::forever('website_description', App\Models\Setting::where('name', 'website_description')->first());
}