prefetch all entries in java caffeine cache

风流意气都作罢 提交于 2019-12-25 07:16:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!