-
Notifications
You must be signed in to change notification settings - Fork 107
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: improve caching - adds TTL, cacheTransport and cacheGetKey #739
Conversation
Signed-off-by: Ilya Amelevich <ilya.amelevich@gmail.com>
Pull Request Test Coverage Report for Build 5069068464
💛 - Coveralls |
What about performance before and after these changes? |
I'm not sure are there exists any preformance tests to measure it. Probably you can help me with that? The best approach for caching - let user define cache logic and transport for caching. Just provide interface. I will try to do that when will have some free time. Current solution just make built-in caching more useful, cause for a lot of usage scenarios it's not enough to cache only first response. |
refactor: move default cache implementation to the separate file Signed-off-by: Ilya Amelevich <ilya.amelevich@gmail.com>
Signed-off-by: Ilya Amelevich <ilya.amelevich@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamelevich this looks great! Thanks for the contribution. 🙇 I just have one small suggestion.
Signed-off-by: Ilya Amelevich <ilya.amelevich@gmail.com>
@lance Done. Please check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iamelevich thanks again for this contribution!
Problem
Current cache implementation not really useful in production, because it can store only first response, but this behaviour not good for a lot of cases. For example: I'm using Circuit Breaker to get config data and endpoint returns different responses based on arguments. I want it to be cached, but based on parameters.
Solution
options.cacheTransport
you can implement cache solution that you want.cacheTTL
option to update cached value after expiration time.cacheGetKey
option to implement way how to get cache key from arguments.Problems
cacheTransport
should be sync, so you can only implement something that don't need async operations.JSON.stringify
and this is not optimal solution, so better to customize it.