當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。