-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat: add option to reset ttl on consecutive cache fill #59
Conversation
This is useful and relevant, can it be reviewed? |
I can create an alternate PR without version bumps and with a test, if that would help. |
thanks! |
@kibertoad there's no conflicts because your PR is clean, so merged and i'll just roll into 10.1.0; ideally we don't change versions in the PRs because they could sit a while. |
@avoidwork Thank you! |
It was the behavior up to 8.0.0, so this shouldn't have been merged if i understand the goal... you just wanted the 'if' condition removed with 8.0.0 returned? |
I think it's easiest to say <8.0.0 the automatic 'keep ttl' behavior was an edge case for most uses, and people were coding around it with the now private 'has()' and other forms of inspection which can tank performance. Instead of removing the conditional statement I should've introduced a second parameter like this PR. |
Either one work, since I am aware of the flag existence, I can configure cache to behave in whatever way I need in my own use-cases. |
Checked my work notes, this was the issue:
So 8.0.0 changed to an explicit expiration as a safer behavior. |
Or said differently, a successful & useful implementation of <8.0.0 runs the risk of never expiring items :) |
Feel free to open a PR to change that new param to 'true', semver bump to reset behavior with fixed api makes sense to me if other people want it; i think it'd best be done by setting the default from an instance attribute, which defaults to 'true' now. |
Wanted to clarify, it was never time centric, it was just being misapplied as a signal to perform that 'increment ttl (this is a get)'. |
Have been using this library in a large scale project for caching states for thousands of requests and we noticed that it was missing an option to reset the ttl of an item if you simply use cache.set(key, item) of an already existing key.
Even the option of using
bypass
doesn't work here as the value already exist in the cache so there is no option other than maybe deleting the item first and then re-adding it which in an asynchronous app could mean that requests will actually miss the cache for a short period of time.Adding a simple flag on the set() method that will reset the ttl would be a handy option as otherwise an item will still expire despite being re-cached correctly.