Laravel key is remembered forever

I have this piece of code that I thought would be remembered forever:

$setting = \Cache::remember('website_description', 0,  function() {
  return App\Models\Setting::where('name', 'website_description')->first();
});

But he does not remember at all, someone told me that passing a function 0to remember will make him remember forever. Since this does not work, in what other way can I put an item in the cache forever?

+4
source share
2 answers

Just change rememberto rememberForeverand remove the time parameter

 $setting = \Cache::rememberForever('website_description', function() {
            return App\Models\Setting::where('name', 'website_description')->first();
        });

Link for remembering Forever

+15
source

You can try the following:

if (! \Cache::has('website_description')) {
    \Cache::forever('website_description', App\Models\Setting::where('name', 'website_description')->first());
}
+2
source

Source: https://habr.com/ru/post/1658544/


All Articles