本文整理汇总了Java中com.google.common.cache.Cache.get方法的典型用法代码示例。如果您正苦于以下问题:Java Cache.get方法的具体用法?Java Cache.get怎么用?Java Cache.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.cache.Cache
的用法示例。
在下文中一共展示了Cache.get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import com.google.common.cache.Cache; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T get(String cacheName, String key) {
try {
Cache<String, Object> cache = getCacheHolder(cacheName);
if (cache != null) {
Object result = cache.get(key, new Callable<Object>() {
@Override
public Object call() throws Exception {
return _NULL;
}
});
if (result != null && !_NULL.equals(result)) {
return (T) result;
}
}
} catch (Exception e) {
logger.warn("get LEVEL1 cache error", e);
}
return null;
}
示例2: get
import com.google.common.cache.Cache; //导入方法依赖的package包/类
private Schema<?> get(final Class<?> cls, Cache<Class<?>, Schema<?>> cache) {
try {
return cache.get(cls, () -> RuntimeSchema.createFrom(cls));
} catch (ExecutionException e) {
return null;
}
}
示例3: get
import com.google.common.cache.Cache; //导入方法依赖的package包/类
private Schema<?> get(final Class<?> cls, Cache<Class<?>, Schema<?>> cache) {
try {
return cache.get(cls, new Callable() {
@Override
public Object call() throws Exception {
return RuntimeSchema.createFrom(cls);
}
});
} catch (ExecutionException e) {
return null;
}
}
示例4: getUnchecked
import com.google.common.cache.Cache; //导入方法依赖的package包/类
static <K, V> V getUnchecked(Cache<K, V> cache, K key, Supplier<V> supplier) {
try {
return cache.get(key, supplier::get);
} catch(ExecutionException e) {
throw Throwables.propagate(e);
}
}
示例5: getAndLoadIfNotPresent
import com.google.common.cache.Cache; //导入方法依赖的package包/类
private BitSet getAndLoadIfNotPresent(final Query query, final LeafReaderContext context) throws IOException, ExecutionException {
final Object coreCacheReader = context.reader().getCoreCacheKey();
final ShardId shardId = ShardUtils.extractShardId(context.reader());
if (shardId != null // can't require it because of the percolator
&& index.getName().equals(shardId.getIndex()) == false) {
// insanity
throw new IllegalStateException("Trying to load bit set for index [" + shardId.getIndex()
+ "] with cache of index [" + index.getName() + "]");
}
Cache<Query, Value> filterToFbs = loadedFilters.get(coreCacheReader, new Callable<Cache<Query, Value>>() {
@Override
public Cache<Query, Value> call() throws Exception {
context.reader().addCoreClosedListener(BitsetFilterCache.this);
return CacheBuilder.newBuilder().build();
}
});
return filterToFbs.get(query,new Callable<Value>() {
@Override
public Value call() throws Exception {
final IndexReaderContext topLevelContext = ReaderUtil.getTopLevelContext(context);
final IndexSearcher searcher = new IndexSearcher(topLevelContext);
searcher.setQueryCache(null);
final Weight weight = searcher.createNormalizedWeight(query, false);
final Scorer s = weight.scorer(context);
final BitSet bitSet;
if (s == null) {
bitSet = null;
} else {
bitSet = BitSet.of(s.iterator(), context.reader().maxDoc());
}
Value value = new Value(bitSet, shardId);
listener.onCache(shardId, value.bitset);
return value;
}
}).bitset;
}
示例6: findCached
import com.google.common.cache.Cache; //导入方法依赖的package包/类
protected <T> T findCached(Class<T> type, Key key, Callable<T> c) {
if (type == null || key == null) {
return null;
}
Optional<?> cached;
synchronized (type) {
Cache<Key, Optional<?>> cache = singleCache.computeIfAbsent(type, t -> createCache());
try {
cached = cache.get(key, () -> {
T value = c.call();
log.trace("Cached : {} - {}", key, value);
return Optional.ofNullable(value);
});
} catch (Exception e) {
log.warn("Failed to cache : {} - {}", type, e);
cached = Optional.empty();
}
}
return type.cast(cached.orElse(null));
}
示例7: listCached
import com.google.common.cache.Cache; //导入方法依赖的package包/类
protected <T> List<T> listCached(Class<T> type, Key key, Callable<List<T>> c) {
if (type == null || key == null) {
return emptyList();
}
Optional<List<?>> cached;
synchronized (type) {
Cache<Key, Optional<List<?>>> cache = listCache.computeIfAbsent(type, t -> createCache());
try {
cached = cache.get(key, () -> {
List<T> values = trimToEmpty(c.call());
log.trace("Cached list : {} ({})", key, values.size());
return Optional.of(values);
});
} catch (Exception e) {
log.warn("Failed to cache list : {} - {}", type, e);
cached = Optional.empty();
}
}
return cached.orElse(emptyList()).stream().map(type::cast).collect(Collectors.toList());
}