当前位置: 首页>>代码示例>>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;未经允许,请勿转载。