-
Notifications
You must be signed in to change notification settings - Fork 11.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.3] Fix cache get minutes #13869
[5.3] Fix cache get minutes #13869
Conversation
…hat varies across different drivers
|
@@ -490,7 +490,7 @@ protected function getMinutes($duration) | |||
$duration = Carbon::now()->diffInSeconds(Carbon::instance($duration), false) / 60; | |||
} | |||
|
|||
return $duration > 0 ? $duration : null; | |||
return (int) ($duration * 60) > 0 ? $duration : null; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It means if duration is less than 1 second, don't bother store, because we don't know what it is going to do!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, wait, I missread this. I read it as being:
(int) (($duration * 60) > 0 ? $duration : null)
But, of course, PHP's precedence doesn't work like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@halaei it means if duration is less than 1 MINUTE...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means you cannot cache things for less than one minute. See for example https://laracasts.com/discuss/channels/general-discussion/caching-less-than-1-minute?page=1
Travis is confused too. |
Looks correct. 👍 |
Just wanted to let you know that this was a breaking change for one of the libraries in my application. |
Laravel does not follow semver. We have plenty of breaking changes in 5.3. This was intentional. We specifically put itto 5.3 rather than 5.2 because it was breaking. |
Not a problem, just wanted to let you know in case you did! |
Cache::put() will never Call Store::put() when $minutes is too close to zero, which can mean caching forever, or for 1 second, or for zero second. If someone needs to cache forever, he/she should call Cache::forever(). If someone do Cache::getStore()->put(), the behavior varies across different stores. Maybe no one does that!