Reputation: 13035
Q: How to create sessions with different lifetimes in Laravel 5?
This question is not a duplicate of this question. I do not want to use it for any kind of sign in or register. I simply want to store it for 5mins because the call to fetch this data sits on a different server and takes a while to fetch.
The problem is that I have another session that needs to be stored for longer and currently using the global config for this session:
/*
|---------------------------------
| Session Lifetime
|---------------------------------
*/
'lifetime' => 30,
'expire_on_close' => true,
How can I give them different lifetimes? Thanks!
Upvotes: 2
Views: 788
Reputation: 40653
For your particular case you should use the cache instead. I generally do:
$value = Cache::remember('key', now()->addMinutes(5), function () {
/* get and return the value if it's not in the cache */
});
remember
is a convenience method to either get the value from cache or run the callback, put the result in the cache and return the result (meaning the next call will just hit the cache).
More information can be found in the documentation under Retrieve & Store
Upvotes: 1