guava源码阅读计划

guava CacheLoader

2017-08-03  本文已影响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> 根据现有的实例返回缓存加载器。
上一篇 下一篇

猜你喜欢

热点阅读