guava CacheLoader

作者: 熊熊要更努力 | 来源:发表于2017-08-03 22:58 被阅读707次
函数 返回值 说明
asyncReloading<K,V> (loader, Executor executor) static <V> CacheLoader<Object,V> 基于现有函数实例返回缓存加载器
load(K key) abstract V 计算或检索与key值对应的值
loadAll(Iterable<? extends K> keys) Map<K,V> 计算或检索与key值集合对应的map集合。
reload(K key, V oldValue) ListenableFuture<V> 计算或检索与已缓存的key对应的替换值
from(Function<K,V> function) static <K,V> CacheLoader<K,V> 基于现有函数实例返回缓存加载器。
from(Supplier<V> supplier) static <V> CacheLoader<Object,V> 根据现有的实例返回缓存加载器。

计算或检索基于密钥的值,用于填充LoadCache。
大多数实现只需要实现load(K)。其他方法可能会根据需要进行覆盖。
运用实例
CacheLoader<Key, Graph> loader = new CacheLoader<Key, Graph>() {
public Graph load(Key key) throws AnyException {
return createExpensiveGraph(key);
}
};
LoadingCache<Key, Graph> cache = CacheBuilder.newBuilder().build(loader);

函数 返回值 说明
asyncReloading<K,V> (loader, Executor executor) static <V> CacheLoader<Object,V> 基于现有函数实例返回缓存加载器
load(K key) abstract V 计算或检索与key值对应的值
loadAll(Iterable<? extends K> keys) Map<K,V> 计算或检索与key值集合对应的map集合。
reload(K key, V oldValue) ListenableFuture<V> 计算或检索与已缓存的key对应的替换值
from(Function<K,V> function) static <K,V> CacheLoader<K,V> 基于现有函数实例返回缓存加载器。
from(Supplier<V> supplier) static <V> CacheLoader<Object,V> 根据现有的实例返回缓存加载器。

相关文章

网友评论

    本文标题:guava CacheLoader

    本文链接:https://www.haomeiwen.com/subject/beemlxtx.html