Support the ongoing development of Laravel.io →
posted 10 years ago
Cache
Last updated 2 years ago.
0

put takes key, data and minutes, not an expiry time. If you want to add an expiry time you'll have to extend it to support that.

https://github.com/laravel/framework/blob/master/src/Illuminate/Cache/StoreInterface.php#L13

Last updated 2 years ago.
0

I looked at the documentation on Laravel's site for cache and used the example.

http://laravel.com/docs/cache

Using Carbon Objects To Set Expire Time

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

Guess I'm confused. The documentation says it's ok to pass a Carbon Object.

Last updated 2 years ago.
0

I looked through the code and it doesn't check for a Carbon Object, it just looks at it in terms of minutes. :/

Looks like documentation error since it doesn't work with Carbon.

After a quick test, even though it says the parameter is an INT, I passed in a decimal and the cache works for under 1 minute.

Last updated 2 years ago.
0

Sorry, it's not a documentation error it was mine. The cache class isn't used directly, it's used through the repository class that adds the support for Carbon, as seen here: https://github.com/illuminate/cache/blob/master/Repository.php#L236 my bad! Not sure why it isn't working for you.

Last updated 2 years ago.
0

Oh interesting. Ya, doesn't work when I pass the Carbon Object. But it does work when passing a decimal.

Thanks for the help. It's working now, just slightly different than how I wanted. If I have time I'll dig into why it's not working with Carbon.

Last updated 2 years ago.
0

nothing fancy, as you add seconds to DateTime, the "getMinutes" method in Repo return a zero value ...

$duration = Carbon::now()->addSeconds(20);

return max( 0, Carbon::now()->diffInMinutes( $duration, false ) ); // return 0

When this value is stored, a zero value means forever.

the decimal approach seems the only way to store in seconds or as mentioned by @citricsquid, extend the repo and the cache driver.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.