I have this piece of code that I thought would remember cache forever:
$setting = \Cache::remember('website_description', 0, function() {
return App\Models\Setting::where('name', 'website_description')->first();
});
But it doesn't remember at all, someone told me that passing 0
to remember function would make it remember forever. Since this doesn't work what other way can I put an item in cache forever?
Just change remember
to rememberForever
and remove time parameter
$setting = \Cache::rememberForever('website_description', function() {
return App\Models\Setting::where('name', 'website_description')->first();
});
Referance for rememberForever
You can try this:
if (! \Cache::has('website_description')) {
\Cache::forever('website_description', App\Models\Setting::where('name', 'website_description')->first());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With