[12.x] Use big integers for database cache expiration column#59243
Merged
taylorotwell merged 1 commit intolaravel:12.xfrom Mar 17, 2026
Merged
[12.x] Use big integers for database cache expiration column#59243taylorotwell merged 1 commit intolaravel:12.xfrom
taylorotwell merged 1 commit intolaravel:12.xfrom
Conversation
Contributor
Author
|
Potential follow-up: increase the threshold for "forever" cache items for the database cache driver to more than ~10 years. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The database cache driver treats "forever" cache items as having an expiry of ~10 years from the current time. From sometime in mid-late Jan 2028, any cache addition without an explicitly given shorter TTL will start causing "out of range" exceptions on database platforms that use 4 byte integer columns (most, with a notable exception of SQLite).
This means that applications using a cache table as it is currently with the database cache driver will face this issue relatively soon, and will need to run a database migration to address the issue. By changing the cache table migration stub, we can mitigate that hassle for future applications.
To reproduce:
Solution:
Use big integers (four bytes of extra storage per row). Simplest, most backwards-compatible way I could think of implementing this.
Note: doesn't affect existing cache tables, only new ones created from the stub, e.g. using
php artisan make:cache-table.Considerations:
Extra storage size. Somewhat negligible these days, and considering that every cache record is stored with a key that has a prefix of several characters, e.g.
app_name_cache:, the extra impact of 4 bytes seems small.Performance: I'm not invested in this enough to run benchmarks. Probably negligible?
Alternatives considered:
timestampcolumn (MySQL timestamp columns are signed 4 byte values, so same issue. SQLite has notimestampcolumn type, so also potentially problematic)integer(no extra storage), but this has limited support, e.g. PostgreSQL does not support unsigned integers.datetimecolumn (one byte of extra storage per row), but this has potential timezone/DST handling issues, particularly for applications with anapp.timezonethat is not set to UTC.Notes:
A test could be added to
DatabaseCacheStoreTestto ensure the expiration value is stored correctly and not clipped, e.g.:But this requires a change in
orchestra/testbench: https://github.com/orchestral/testbench-core/blob/11.x/laravel/migrations/0001_01_01_000001_testbench_create_cache_table.php