Asked 7 years ago
27 Jan 2017
Views 1499
sandip

sandip posted

how to use cache in Laravel ?

how to use cache in Laravel ? is use of Laravel cache help make web page faster ? what is the cache module i can use with Laravel ? is there extra installation required to use cache in Laravel ?
Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

one can retrieve cache value directly by cache function , its global function which help to get value for particular key at any stage of web page.


$value = cache('filename');


it is easy to retrieve stored cache data by cache global function .

noob

noob
answered Nov 30 '-1 00:00

what is the cache driver i can use with Laravel ?

1. file storage
2. database
3. redis
4. Memcached
shyam

shyam
answered Nov 30 '-1 00:00

Yes Cache always help to make web page faster . and it is apply to all web programming Languages or framework . Laravel also use cache which really help make web page faster .

How to use Cache In Laravel ?

1.Configure cache
decide Which Cache you want to use and configure at configuration file

2. Use cache
you need to load lib for it where you want to use
suppose if you decide to use Cache facade than

use Illuminate\Support\Facades\Cache;


if you decide to use Redis facade, than

use Illuminate\Support\Facades\Redis;


how to get/set Cache content ?

Cache::set , Cache::get , Cache::pull , Cache::put etc..
so its use like this

$expiresAt = Carbon::now()->addMinutes(10);
Cache::put('key', 'value', $expiresAt);
if (Cache::has('key')) {
 $value = Cache::get('key');

}



Using the Cache facade, you may access various cache stores via the store method.


$value = Cache::store('file')->get('foo');

Cache::store('redis')->put('bar', 'baz', 10);

Post Answer