本文整理汇总了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());
}