Skip to content
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

Cannot create a cache for one second after upgrading to Laravel 11 #53425

Closed
GalahadXVI opened this issue Nov 6, 2024 · 2 comments
Closed

Cannot create a cache for one second after upgrading to Laravel 11 #53425

GalahadXVI opened this issue Nov 6, 2024 · 2 comments

Comments

@GalahadXVI
Copy link

GalahadXVI commented Nov 6, 2024

Laravel Version

11.30.0

PHP Version

8.3.13

Database Driver & Version

No response

Description

I recently upgraded from Laravel 10.48.22 to Laravel 11.30.0 and all implementations of

cache()->remember($key, $value, now()->addSecond()) have broke.

However, this works:
cache()->remember($key, $value, 1)

Switching back to Laravel 10 fixed the issue.

I'm not sure if this is intentional or not - but it's undocumented and it caused our app to break.

image
image

Both tests for Laravel 10 + 11 using Carbon 2.72.5.

Steps To Reproduce

Just run the following:

return [
  cache()->put("test_1", true, now()->addSecond()), 
  cache()->put("test_1", true, 1), 
  cache()->put("test_2", true, now()->addSeconds(2))
];

And it will output:

[
    false,
    true,
    true,
  ]

Interestingly, if the order changes, then it will output as true for all values.

return [
cache()->put("test_1", true, 1), 
cache()->put("test_1", true, now()->addSecond()), 
cache()->put("test_2", true, now()->addSeconds(2))
];

will output:

[
    true,
    true,
    true,
  ]
@timacdonald
Copy link
Member

This issue is caused by time progressing during the execution of the PHP script.

You pass through now()->addSecond(), but by the time we actually can extract the time into the future of that value, microseconds have passed.

This results in a value of ~0.9999 seconds, which we cast to an int and it becomes zero.

I've got a fix that should mostly fix this which I'll PR shortly.

@timacdonald
Copy link
Member

PR up: #53431

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants