I have a downstream service which takes the list of ids and return the data for the ids. I am exploring Guava LoadingCache to cache these values. But the loader in the LoadingCache accepts only one key. Are there any ways to use the list of keys.
0
votes
Which list of key? When you call cache.get("foo"), how can the cache know that later, maybe, you will also want the values for "bar" and "baz"? Is that list of key constant?
- JB Nizet
Basically, i want to do cache.getAll(listOfKeys). But loader.load is taking only one key. It means the downstream service should be called for every key.
- Navin GV
And is that listOfKeys always the same?
- JB Nizet
Not all the keys will be same. Some of the keys will be same and some are new keys. I want to collect the new keys and make a service call. For the old keys want to take the data from cache.
- Navin GV
I did a small experimentation, it looks like this can be done by using getAll and loadAll APIs. github.com/google/guava/wiki/CachesExplained#from-a-cacheloader
- Navin GV
1 Answers
0
votes
I did a small experimentation, it looks like this can be done by using getAll and loadAll APIs. https://github.com/google/guava/wiki/CachesExplained#from-a-cacheloader
Sample code available in https://github.com/gvnavin/CachingExperimentations