初识LoadingCache
ps: 范例
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);
}
});
1、创建
1)LoadingCache是附带CacheLoader构建而成的缓存实现。创建CacheLoader通常只需要简单地实现V load(K key) throws Exception方法
2、查询
1)get(K) :从LoadingCache查询的正规方式。这个方法要么返回已经缓存的值,要么使用CacheLoader向缓存原子地加载新值。
ps:
LoadingCache<Key, Graph> graphs = CacheBuilder.newBuilder()
.maximumSize(1000)
.build(
new CacheLoader<Key, Graph>() {
public Graph load(Key key) t