Add implementation for Suppliers#memoizeWithRefresh #3777
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.
In response to #872 (comment) I'd like to submit this PR for discussion.
I began looking into this when trying to find a way to make my apps existing
LoadingCache<K, V>
populate itself with all of the possible keys and values it could from my database table, in my use case the input data is dynamic and contains keys which may or may not have a value in the database however, the database table is quite small and could easily be completely stored in memory and refreshed at a set interval, this will reduce the number of calls my app needs to make to the database exponentially(>10k requests per minute to 1 request per 15 minutes).While searching I came across this issue #775 which is exactly the same problem I am trying to solve but I fear there was some confusion in the reasons why and the use case.
I would prefer if there was an implementation of
LoadingCache
that had these semantics but for now I thought a smaller change would be to add an extra implementation to memoized suppliers.I am aware that the tests here are less than idea, I just followed the convention from the tests of the expiring memoizer which uses
Thread.sleep
.There is a good chance I've missed something which exists that does exactly what I require so if you know if it please tell me 😄