本文整理汇总了Java中com.github.benmanes.caffeine.cache.Caffeine.build方法的典型用法代码示例。如果您正苦于以下问题:Java Caffeine.build方法的具体用法?Java Caffeine.build怎么用?Java Caffeine.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.benmanes.caffeine.cache.Caffeine
的用法示例。
在下文中一共展示了Caffeine.build方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ChannelPool
import com.github.benmanes.caffeine.cache.Caffeine; //导入方法依赖的package包/类
/**
* <p>Constructor for ChannelPool.</p>
*
* @param factory a {@link com.github.ibole.microservice.rpc.client.grpc.ChannelPool.ChannelFactory} object.
* @param initialCapacity the initial capacity of the channel pool
* @param maximumSize the maximum size of the channel pool
* @return the instance of ChannelPool
* @throws java.io.IOException if any.
*/
private ChannelPool(ChannelFactory factory, int initialCapacity, int maximumSize) {
Preconditions.checkArgument(factory != null,
"ChannelFactory cannot be null.");
Preconditions.checkArgument(initialCapacity > 0,
"Channel initial capacity has to be a positive number.");
Preconditions.checkArgument(maximumSize > 0,
"Channel maximum size has to be a positive number.");
Preconditions
.checkArgument(maximumSize >= initialCapacity,
"The maximum size of channel pool has to be greater than or equal to the initial capacity.");
Caffeine<String, InstrumentedChannel> caffeine = Caffeine.newBuilder().initialCapacity(initialCapacity).maximumSize(maximumSize).weakKeys()
.softValues().removalListener(new ChannelRemovalListener());
this.factory = factory;
channelPool = caffeine.build();
}
示例2: LRUCache
import com.github.benmanes.caffeine.cache.Caffeine; //导入方法依赖的package包/类
/**
* Constructs an empty <tt>LRUCache</tt> instance with the
* specified initial capacity, maximumCacheSize,load factor and ordering mode.
*
* @param initialCapacity the initial capacity.
* @param maximumCacheSize the max capacity.
* @param stopOnEviction whether to stop service on eviction.
* @param soft whether to use soft values a soft cache (default is false)
* @param weak whether to use weak keys/values as a weak cache (default is false)
* @param syncListener whether to use synchronous call for the eviction listener (default is false)
* @throws IllegalArgumentException if the initial capacity is negative
*/
public LRUCache(int initialCapacity, int maximumCacheSize, boolean stopOnEviction,
boolean soft, boolean weak, boolean syncListener) {
Caffeine<K, V> caffeine = Caffeine.newBuilder()
.initialCapacity(initialCapacity)
.maximumSize(maximumCacheSize)
.removalListener(this);
if (soft) {
caffeine.softValues();
}
if (weak) {
caffeine.weakKeys();
caffeine.weakValues();
}
if (syncListener) {
caffeine.executor(Runnable::run);
}
this.cache = caffeine.build();
this.map = cache.asMap();
this.maxCacheSize = maximumCacheSize;
this.stopOnEviction = stopOnEviction;
}