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
Try to get the value first to avoid creating a lambda #68
Conversation
Apply some IntelliJ inspection recommendations.
@guidomedina I mad some comments in the code. |
@svendiedrichsen I can't see your comments, I don't know what to do, I even tried from an incognito session and your comments are not there. |
@guidomedina If you are logged in you can see them right in this conversation or when you are looking at the 'Files changed' tab. |
final String key = valueHandler.getKey(); | ||
// Try to first get the value which is most likely cached to avoid creating a lambda. | ||
final VALUE value = cachingMap.get(key); | ||
return value != null ? value : cachingMap.computeIfAbsent(key, k -> valueHandler.createValue()); |
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.
@svendiedrichsen can you see this comment? I know where comments are made in the code, but trust me when I tell you that I cannot see your comments.
Comments:
|
If the function were static and not a lambda dynamically created the difference would be very minimal; for caches with high reading pattern vs write calling first get is more effective. For example, in SimpleCache there is a pre-defined loading function for the whole cache and not one created per key. |
Ok, sounds good to me then. Thanks for the work. |
Try to get the value first which is most likely to be cached to avoid creating a lambda.
Similar to:
https://github.com/quickfix-j/quickfixj/blob/master/quickfixj-core/src/main/java/org/quickfixj/SimpleCache.java
I was going to submit this PR yesterday but I was so busy that got distracted and forgot.