当前位置: 首页>>代码示例>>Java>>正文


Java Caffeine.build方法代码示例

本文整理汇总了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();
}
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:26,代码来源:ChannelPool.java

示例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;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:35,代码来源:LRUCache.java


注:本文中的com.github.benmanes.caffeine.cache.Caffeine.build方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。