问题
I am trying to build a cache using https://github.com/ben-manes/caffeine, where I need to fetch all entries during boot up time and I do not know all the keys before hand. My CachLoader has something like this and trying to cache all at startup. But looks like I will need to know all the keys before hand, if I want to prefetch all entries in to cache? Am I missing anything?
So, say I call cache.getAll(10) and only 10-->100 will be cached even though the loadAll method returns 3 entries (10-->100, 20-->400, 30-->900)
@Override
public Map<Integer, Integer> loadAll(Iterable<? extends Integer> keys)
{
// gets called for the keys which are not present in the cache only by getAll
// we will load all keys irrespective of what is passed in
System.out.println("in loadAll");
// problem here is it is only caching the supplied keys
Map<Integer, Integer> map = new HashMap<Integer, Integer>();
map.put(10, 100);
map.put(20, 400);
map.put(30, 900);
return map;
}
来源:https://stackoverflow.com/questions/37534666/prefetch-all-entries-in-java-caffeine-cache