本文整理了Java中com.google.common.cache.Cache.get()
方法的一些代码示例,展示了Cache.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cache.get()
方法的具体详情如下:
包路径:com.google.common.cache.Cache
类名称:Cache
方法名:get
[英]Returns the value associated with key in this cache, first loading that value if necessary. No observable state associated with this cache is modified until loading completes.
[中]
代码示例来源:origin: apache/incubator-druid
@Override
public V get(K key, Callable<? extends V> valueLoader) throws ExecutionException
{
return cache.get(key, valueLoader);
}
代码示例来源:origin: thinkaurelius/titan
@Override
public InternalVertex get(final long id, final Retriever<Long, InternalVertex> retriever) {
final Long vertexId = id;
InternalVertex vertex = cache.getIfPresent(vertexId);
if (vertex == null) {
InternalVertex newVertex = volatileVertices.get(vertexId);
if (newVertex == null) {
newVertex = retriever.get(vertexId);
}
assert newVertex!=null;
try {
vertex = cache.get(vertexId, new NewVertexCallable(newVertex));
} catch (Exception e) { throw new AssertionError("Should not happen: "+e.getMessage()); }
assert vertex!=null;
}
return vertex;
}
代码示例来源:origin: apache/hive
/**
* Retrieves an item from the cache, and if its not there, it will use the valueLoader to load it and cache it.
*/
public V get(K key, Callable<V> valueLoader) throws ExecutionException {
return cacheL1.get(key, () -> cacheL2.get(key, valueLoader));
}
}
代码示例来源:origin: google/guava
/** @since 11.0 */
@Override
public V get(K key, Callable<? extends V> valueLoader) throws ExecutionException {
return delegate().get(key, valueLoader);
}
代码示例来源:origin: google/j2objc
/** @since 11.0 */
@Override
public V get(K key, Callable<? extends V> valueLoader) throws ExecutionException {
return delegate().get(key, valueLoader);
}
代码示例来源:origin: wildfly/wildfly
/** @since 11.0 */
@Override
public V get(K key, Callable<? extends V> valueLoader) throws ExecutionException {
return delegate().get(key, valueLoader);
}
代码示例来源:origin: yu199195/hmily
private Schema<?> get(final Class<?> cls, final Cache<Class<?>, Schema<?>> cache) {
try {
return cache.get(cls, () -> RuntimeSchema.createFrom(cls));
} catch (ExecutionException e) {
return null;
}
}
代码示例来源:origin: codingapi/tx-lcn
private Schema<?> get(final Class<?> cls, Cache<Class<?>, Schema<?>> cache) {
try {
return cache.get(cls, () -> RuntimeSchema.createFrom(cls));
} catch (ExecutionException e) {
e.printStackTrace();
return null;
}
}
代码示例来源:origin: apache/incubator-gobblin
@Override
public List<ConfigKeyPath> getOwnImports(ConfigKeyPath configKey, Optional<Config> runtimeConfig) {
try {
return this.ownImportMap.get(configKey, () -> this.fallback.getOwnImports(configKey, runtimeConfig));
} catch (ExecutionException ee) {
throw new RuntimeException(ee);
}
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public LookupResult get(LookupCacheKey key, Callable<LookupResult> loader) {
try (final Timer.Context ignored = lookupTimer()) {
return cache.get(key, loader);
} catch (ExecutionException e) {
LOG.warn("Loading value from data adapter failed for key {}, returning empty result", key, e);
return LookupResult.empty();
}
}
代码示例来源:origin: thinkaurelius/titan
public SliceQuery getQuery(final InternalRelationType type, Direction dir) {
CacheEntry ce;
try {
ce = cache.get(type.longId(),new Callable<CacheEntry>() {
@Override
public CacheEntry call() throws Exception {
return new CacheEntry(edgeSerializer,type);
}
});
} catch (ExecutionException e) {
throw new AssertionError("Should not happen: " + e.getMessage());
}
assert ce!=null;
return ce.get(dir);
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Constructs a {@link Path} that points to the location of the given version of the {@link ConfigStore} on HDFS. If
* this {@link Path} does not exist, a {@link VersionDoesNotExistException} is thrown.
*/
private Path getVersionRoot(String version) throws VersionDoesNotExistException {
try {
return this.versions.get(version, new VersionRootLoader(version));
} catch (ExecutionException e) {
throw new RuntimeException(
String.format("Error while checking if version \"%s\" for store \"%s\" exists", version, getStoreURI()), e);
}
}
代码示例来源:origin: JanusGraph/janusgraph
public SliceQuery getQuery(final InternalRelationType type, Direction dir) {
CacheEntry ce;
try {
ce = cache.get(type.longId(), () -> new CacheEntry(edgeSerializer,type));
} catch (ExecutionException e) {
throw new AssertionError("Should not happen: " + e.getMessage());
}
assert ce!=null;
return ce.get(dir);
}
代码示例来源:origin: google/guava
public void testLoader() throws ExecutionException {
final Cache<Integer, Integer> cache = CacheBuilder.newBuilder().build();
Callable<Integer> loader =
new Callable<Integer>() {
private int i = 0;
@Override
public Integer call() throws Exception {
return ++i;
}
};
cache.put(0, 10);
assertEquals(Integer.valueOf(10), cache.get(0, loader));
assertEquals(Integer.valueOf(1), cache.get(20, loader));
assertEquals(Integer.valueOf(2), cache.get(34, loader));
cache.invalidate(0);
assertEquals(Integer.valueOf(3), cache.get(0, loader));
cache.put(0, 10);
cache.invalidateAll();
assertEquals(Integer.valueOf(4), cache.get(0, loader));
}
代码示例来源:origin: apache/incubator-gobblin
private List<T> doTraverseGraphRecursively(T node, NodePath<T> nodePath) {
try {
return this.traversalCache.get(node, () -> computeRecursiveTraversal(node, nodePath));
} catch (ExecutionException | UncheckedExecutionException ee) {
throw unpackExecutionException(ee);
}
}
代码示例来源:origin: prestodb/presto
@Override
public void serialize(T value, JsonGenerator generator, SerializerProvider provider)
throws IOException
{
if (value == null) {
provider.defaultSerializeNull(generator);
return;
}
try {
Class<?> type = value.getClass();
JsonSerializer<T> serializer = serializerCache.get(type, () -> createSerializer(provider, type));
serializer.serializeWithType(value, generator, provider, typeSerializer);
}
catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause != null) {
throwIfInstanceOf(cause, IOException.class);
}
throw new RuntimeException(e);
}
}
代码示例来源:origin: apache/hive
private static SearchArgument getSearchArgumentFromString(Configuration conf, String sargString) {
try {
return isSargsCacheEnabled(conf)? getSargsCache(conf).get(sargString, () -> create(sargString))
: create(sargString);
}
catch (ExecutionException exception) {
throw new RuntimeException(exception);
}
}
代码示例来源:origin: apache/hive
private static SearchArgument getSearchArgumentFromExpression(Configuration conf, String sargString) {
try {
return isSargsCacheEnabled(conf)?
getSargsCache(conf).get(sargString,
() -> create(conf, SerializationUtilities.deserializeExpression(sargString)))
: create(conf, SerializationUtilities.deserializeExpression(sargString));
}
catch (ExecutionException exception) {
throw new RuntimeException(exception);
}
}
代码示例来源:origin: gocd/gocd
private void checkRateLimitAvailable(Request request, Response response) throws ExecutionException {
TokenBucket tokenBucket = rateLimiters.get(currentUsername(), () -> TokenBuckets.builder()
.withCapacity(requestsPerMinute)
.withInitialTokens(requestsPerMinute)
.withRefillStrategy(new FixedIntervalRefillStrategy(ticker, requestsPerMinute, 1, TimeUnit.MINUTES))
.build());
response.header("X-RateLimit-Limit", String.valueOf(requestsPerMinute));
response.header("X-RateLimit-Remaining", String.valueOf(tokenBucket.getNumTokens()));
if (!tokenBucket.tryConsume()) {
throw HaltApiResponses.haltBecauseRateLimitExceeded();
}
}
}
代码示例来源:origin: thinkaurelius/titan
@Override
public void read(Message message) {
ReadBuffer content = message.getContent().asReadBuffer();
String senderId = message.getSenderId();
TransactionLogHeader.Entry txentry = TransactionLogHeader.parse(content,serializer,times);
TransactionLogHeader txheader = txentry.getHeader();
StandardTransactionId transactionId = new StandardTransactionId(senderId,txheader.getId(),
txheader.getTimestamp());
TxEntry entry;
try {
entry = txCache.get(transactionId,entryFactory);
} catch (ExecutionException e) {
throw new AssertionError("Unexpected exception",e);
}
entry.update(txentry);
}
内容来源于网络,如有侵权,请联系作者删除!