本文整理匯總了Java中com.github.benmanes.caffeine.cache.Caffeine.from方法的典型用法代碼示例。如果您正苦於以下問題:Java Caffeine.from方法的具體用法?Java Caffeine.from怎麽用?Java Caffeine.from使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.github.benmanes.caffeine.cache.Caffeine
的用法示例。
在下文中一共展示了Caffeine.from方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: RepositoryCache
import com.github.benmanes.caffeine.cache.Caffeine; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
public RepositoryCache(String cacheSpec) {
this.cacheSpec = requireNonNull(cacheSpec, "cacheSpec");
final Caffeine<Object, Object> builder = Caffeine.from(cacheSpec);
if (cacheSpec.contains("maximumWeight=")) {
builder.weigher((Weigher<CacheableCall, Object>) CacheableCall::weigh);
}
cache = builder.recordStats()
.buildAsync((key, executor) -> {
logger.debug("Cache miss: {}", key);
return key.execute();
});
}
示例2: ProtobufRedisLoadingCache
import com.github.benmanes.caffeine.cache.Caffeine; //導入方法依賴的package包/類
ProtobufRedisLoadingCache(
String name,
K keyPrototype,
V valuePrototype,
Duration redisTtl,
@Nullable CaffeineSpec localCacheSpec,
RedisClusterClient redisClient) {
checkNotNull(keyPrototype, "keyPrototype");
checkNotNull(valuePrototype, "valuePrototype");
checkNotNull(redisTtl, "redisTtl");
checkNotNull(redisClient, "redisClient");
redis =
redisClient
.connect(
new ProtobufRedisCodec<>(
(name + ":").getBytes(StandardCharsets.UTF_8), keyPrototype, valuePrototype))
.async();
final Caffeine<Object, Object> caffeineBuilder =
localCacheSpec != null
? Caffeine.from(localCacheSpec)
: Caffeine.newBuilder().maximumSize(0);
cache =
caffeineBuilder
.executor(CurrentRequestContextExecutor.INSTANCE)
.buildAsync((k, executor) -> redis.get(k).toCompletableFuture());
setArgs = SetArgs.Builder.px(redisTtl.toMillis());
}