Google Guava的缓存在阅读https://github.com/google/guava/wiki/CachesExplained
之后非常棒LoadingCache<Key, Graph> graphs = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterWrite(10, TimeUnit.MINUTES)
.removalListener(MY_LISTENER)
.build(
new CacheLoader<Key, Graph>() {
public Graph load(Key key) throws AnyException {
return createExpensiveGraph(key);
}
});
我想要实现的内容需要满足以下要求:
createExpensiveGraph(key)
来更新并重置计时器(expireAfterWrite
已经这样做我相信)。createExpensiveGraph(key)
的下一次通话失败,即使下一次通话在10分钟后发生,我仍然希望使用旧值。我认为1,它是番石榴LoadingCache
的本质,但对于2,我们如何在保持1的同时实现它呢?