當前位置: 首頁>>代碼示例>>Java>>正文


Java CacheBuilder.concurrencyLevel方法代碼示例

本文整理匯總了Java中com.google.common.cache.CacheBuilder.concurrencyLevel方法的典型用法代碼示例。如果您正苦於以下問題:Java CacheBuilder.concurrencyLevel方法的具體用法?Java CacheBuilder.concurrencyLevel怎麽用?Java CacheBuilder.concurrencyLevel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.cache.CacheBuilder的用法示例。


在下文中一共展示了CacheBuilder.concurrencyLevel方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: DefaultSimpleCache

import com.google.common.cache.CacheBuilder; //導入方法依賴的package包/類
/**
 * Construct a cache using the specified capacity and name.
 * 
 * @param maxItems The cache capacity. 0 = use {@link #DEFAULT_CAPACITY}
 * @param useMaxItems Whether the maxItems value should be applied as a size-cap for the cache.
 * @param cacheName An arbitrary cache name.
 */
@SuppressWarnings("unchecked")
public DefaultSimpleCache(int maxItems, boolean useMaxItems, int ttlSecs, int maxIdleSecs, String cacheName)
{
    if (maxItems == 0)
    {
        maxItems = DEFAULT_CAPACITY;
    }
    else if (maxItems < 0)
    {
        throw new IllegalArgumentException("maxItems may not be negative, but was " + maxItems);
    }
    this.maxItems = maxItems;
    this.useMaxItems = useMaxItems;
    this.ttlSecs = ttlSecs;
    this.maxIdleSecs = maxIdleSecs;
    setBeanName(cacheName);
    
    // The map will have a bounded size determined by the maxItems member variable.
    @SuppressWarnings("rawtypes")
    CacheBuilder builder = CacheBuilder.newBuilder();
    
    if (useMaxItems)
    {
        builder.maximumSize(maxItems);
    }
    if (ttlSecs > 0)
    {
        builder.expireAfterWrite(ttlSecs, TimeUnit.SECONDS);
    }
    if (maxIdleSecs > 0)
    {
        builder.expireAfterAccess(maxIdleSecs, TimeUnit.SECONDS);
    }
    builder.concurrencyLevel(32);
    
    cache = (Cache<K, AbstractMap.SimpleImmutableEntry<K, V>>) builder.build();
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:45,代碼來源:DefaultSimpleCache.java

示例2: buildCache

import com.google.common.cache.CacheBuilder; //導入方法依賴的package包/類
private void buildCache() {
    long sizeInBytes = MemorySizeValue.parseBytesSizeValueOrHeapRatio(size, INDICES_CACHE_QUERY_SIZE).bytes();

    CacheBuilder<Key, Value> cacheBuilder = CacheBuilder.newBuilder()
            .maximumWeight(sizeInBytes).weigher(new QueryCacheWeigher()).removalListener(this);
    cacheBuilder.concurrencyLevel(concurrencyLevel);

    if (expire != null) {
        cacheBuilder.expireAfterAccess(expire.millis(), TimeUnit.MILLISECONDS);
    }

    cache = cacheBuilder.build();
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:14,代碼來源:IndicesRequestCache.java

示例3: SetCacheImpl

import com.google.common.cache.CacheBuilder; //導入方法依賴的package包/類
/**
 * @param maxSize          the maximum number of entries that the cache can hold
 * @param expireDuration   the length of time after an entry is created that it should be
 *                         automatically removed
 * @param expireUnit       the unit that {@code duration} is expressed in
 * @param concurrencyLevel guides the allowed concurrency among update operations. Used as a
 *                         hint for internal sizing. Refer to Guava CacheBuilder for specific
 *                         details.
 */
public SetCacheImpl(int maxSize, long expireDuration, TimeUnit expireUnit, int concurrencyLevel) {
    CacheBuilder builder = CacheBuilder.newBuilder()
            .maximumSize(maxSize)
            .expireAfterWrite(expireDuration, expireUnit);
    if (concurrencyLevel > 0) {
        builder = builder.concurrencyLevel(concurrencyLevel);
    }

    this.cache = builder.build();
}
 
開發者ID:Asymmetrik,項目名稱:nifi-nars,代碼行數:20,代碼來源:SetCacheImpl.java


注:本文中的com.google.common.cache.CacheBuilder.concurrencyLevel方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。