feat: Add support for callables for TTL in Cache Handlers#10159
Open
patel-vansh wants to merge 8 commits intocodeigniter4:4.8from
Open
feat: Add support for callables for TTL in Cache Handlers#10159patel-vansh wants to merge 8 commits intocodeigniter4:4.8from
patel-vansh wants to merge 8 commits intocodeigniter4:4.8from
Conversation
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: