feat: Add support for callables for TTL in Cache Handlers#10159
Open
patel-vansh wants to merge 9 commits intocodeigniter4:4.8from
Open
feat: Add support for callables for TTL in Cache Handlers#10159patel-vansh wants to merge 9 commits intocodeigniter4:4.8from
patel-vansh wants to merge 9 commits intocodeigniter4:4.8from
Conversation
memleakd
reviewed
May 6, 2026
|
|
||
| - **Database:** ``CodeIgniter\Database\ConnectionInterface`` now requires the ``afterCommit()``, ``afterRollback()``, ``inTransaction()``, and ``transaction()`` methods. | ||
| - **Cache:** ``CodeIgniter\Cache\CacheInterface::remember()`` now accepts a TTL callable. All built-in cache handlers inherit this method via ``BaseHandler``, so no changes are required for them. | ||
| - **Database:** ``CodeIgniter\Database\ConnectionInterface`` now requires the ``afterCommit()``, ``afterRollback()``, and ``transaction()`` methods. |
Contributor
There was a problem hiding this comment.
This looks like an accidental removal of inTransaction() from the database interface change note.
Contributor
Author
There was a problem hiding this comment.
Oh yeah, I was actually rebasing so, maybe this removal would have taken place. I'll sync it with latest file tomorrow.
memleakd
reviewed
May 6, 2026
Comment on lines
+62
to
+64
| if (is_callable($ttl)) { | ||
| return parent::remember($key, $ttl, $callback); | ||
| } |
Contributor
There was a problem hiding this comment.
This seems to prefix the APCu key twice when the TTL is callable.
With a cache prefix configured, the value gets saved under one key but normal reads look for another, so the cached value cannot be found afterward.
Could the callable TTL path keep the original key and only apply the prefix in the apcu_entry() path?
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.
Description
This PR adds support for callable for TTL in cache handlers.
Many times the following two cases arise while calculating TTLs:
In the first senario, calculating TTL everytime, even if its a cache hit, is redundant. And in second senario, you can't just use the
remember()method. You have to rely on traditionalget()/save()methods.This PR solves both problems by adding support for callables as TTL. The passed callable may optionally accept the computed value as first parameter which solves the second senario.
And by passing callable without any parameter just defers calculating TTL until cache miss.
This can be considered as a Breaking Change as the Interface method's signature is changed. However, the usage of
remember()method remains mostly unchanged.Checklist: