Skip to content

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

@GalahadXVI

Description

@GalahadXVI

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,
  ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions