Laravel Classroom image

Anil  Bist / Professional / Web Technology

 
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!

 

 
 
 
image
Anil  Bist

Skills    Laravel

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)