Laravel Cache, Cookies and Sessions

Cache

Cache::put('key', 'value', $minutes);
Cache::add('key', 'value', $minutes);
Cache::forever('key', 'value');
Cache::remember('key', $minutes, function(){ return 'value' });
Cache::rememberForever('key', function(){ return 'value' });
Cache::forget('key');
Cache::has('key');
Cache::get('key');
Cache::get('key', 'default');
Cache::get('key', function(){ return 'default'; });
Cache::tags('my-tag')->put('key','value', $minutes);
Cache::tags('my-tag')->has('key');
Cache::tags('my-tag')->get('key');
Cache::tags('my-tag')->forget('key');
Cache::tags('my-tag')->flush();
Cache::increment('key');
Cache::increment('key', $amount);
Cache::decrement('key');
Cache::decrement('key', $amount);
Cache::section('group')->put('key', $value);
Cache::section('group')->get('key');
Cache::section('group')->flush();

Cookies

Cookie::get('key');
Cookie::get('key', 'default');
// Create a cookie that lasts for ever
 Cookie::forever('key', 'value');
// Create a cookie that lasts N minutes
 Cookie::make('key', 'value', 'minutes');
// Set a cookie before a response has been created
 Cookie::queue('key', 'value', 'minutes');
// Forget cookie
 Cookie::forget('key');
// Send a cookie with a response
$response = Response::make('Hello World');
// Add a cookie to the response
$response->withCookie(Cookie::make('name', 'value', $minutes));

Sessions

Session::get('key');
// Returns an item from the session
 Session::get('key', 'default');
Session::get('key', function(){ return 'default'; });
// Get the session ID
 Session::getId();
// Put a key / value pair in the session
 Session::put('key', 'value');
// Push a value into an array in the session
 Session::push('foo.bar','value');
// Returns all items from the session
 Session::all();
// Checks if an item is defined
 Session::has('key');
// Remove an item from the session
 Session::forget('key');
// Remove all of the items from the session
 Session::flush();
// Generate a new session identifier
 Session::regenerate();
// Flash a key / value pair to the session
 Session::flash('key', 'value');
// Reflash all of the session flash data
 Session::reflash();
// Reflash a subset of the current flash data
 Session::keep(array('key1', 'key2'));

About the author

Janaki(http://mjanaki.com) - A Software developer with 9+ years of experience in multiple technology projects across web, mobile, and cloud applications with expertise in PHP, C#, MySQL, Web services and open source platforms.

Similar Posts

Leave a reply

required*

Eye Test: * Time limit is exhausted. Please reload CAPTCHA.