Laravel Classroom image

CiliSp
 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3 | 4|
Lessons:-Caching

17.4 A better way
You might find yourself using the has() method to check if a cached item exists, and falling into
this familiar pattern..
1 <?php
2
3 if (! Cache::has('mydata'))
4 {
5 $data = 'complicated_generated_data';
6 Cache::put('mydata', $data, 10);
7 }
8
9 return $data;
However, you can use the remember() method as a much more elegant solution. The remember()
method will return the value if it exists in the cache, or it will store and return the value of the
second parameter for a defined length of time, for example..
1 <?php
2
3 return Cache::remember('mydata', function () {
4 return 'complicated_generated_data';
5 }, 10);
Of course the closure will not be executed unless the key does not exist or has expired.
Have fun using the Cache!

 

 
 
 

CiliSp

Skills    Laravel

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)