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


Java CacheBuilder.build方法代碼示例

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


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

示例1: cacheManager

import com.google.common.cache.CacheBuilder; //導入方法依賴的package包/類
@Bean
public CacheManager cacheManager() {
    log.debug("Creating Guava cache manager");
    CacheBuilder<Object, Object> thirtyMinuteBuilder = CacheBuilder.newBuilder().expireAfterAccess(30, TimeUnit.MINUTES).recordStats();
    CacheBuilder<Object, Object> oneHourBuilder = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.HOURS).recordStats();
    CacheBuilder<Object, Object> threeHoursBuilder = CacheBuilder.newBuilder().expireAfterAccess(3, TimeUnit.HOURS).recordStats();

    Map<String, CacheBuilder<Object, Object>> builderMap = new LinkedHashMap<>();
    builderMap.put("schedule", oneHourBuilder);
    builderMap.put("team", threeHoursBuilder);
    builderMap.put("roster", threeHoursBuilder);
    builderMap.put("results", thirtyMinuteBuilder);
    builderMap.put("legacyPlayer", threeHoursBuilder);
    builderMap.put("player", threeHoursBuilder);
    builderMap.put("banList", threeHoursBuilder);
    builderMap.put("transactions", thirtyMinuteBuilder);
    builderMap.put("overwatch", threeHoursBuilder);

    GuavaCacheManager guavaCacheManager = new GuavaCacheManager() {
        @Override
        protected com.google.common.cache.Cache<Object, Object> createNativeGuavaCache(String name) {
            CacheBuilder<Object, Object> builder = builderMap.get(name);
            if (builder != null) {
                log.debug("Creating cache for {}: {}", name, builder.toString());
                return builder.build();
            }
            log.debug("Creating fallback cache for {}", name);
            return super.createNativeGuavaCache(name);
        }
    };
    guavaCacheManager.setCacheBuilder(thirtyMinuteBuilder);
    return guavaCacheManager;
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:34,代碼來源:CacheConfiguration.java

示例2: BaseProcessingUnit

import com.google.common.cache.CacheBuilder; //導入方法依賴的package包/類
/**
 * Creates a new processing unit.
 *
 * @param name name.
 * @param engine the engine.
 * @param inQueue input queue.
 * @param outQueue output queue.
 */
public BaseProcessingUnit(String name, Engine engine, EventQueue inQueue, EventQueue outQueue) {
    super(name, engine);
    this.inQueue = inQueue;
    this.outQueue = outQueue;

    long cacheExpireTime = engine.getDefaultParameters().getProcessingUnitEventProcessorCacheExpireTime();
    if (cacheExpireTime >= 0) {
        // Turn on the cache.
        CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
        if (cacheExpireTime > 0) {
            builder.expireAfterAccess(cacheExpireTime, TimeUnit.MILLISECONDS);
        }

        eventNameProcessorsCache = builder.build(new CacheLoader<String, Set<AtomicReference<T>>>() {

            @Override
            public Set<AtomicReference<T>> load(String eventName) throws Exception {
                return resolveEventProcessors(eventName);
            }
        });
    }
}
 
開發者ID:softelnet,項目名稱:sponge,代碼行數:31,代碼來源:BaseProcessingUnit.java

示例3: CachedScriptClassInstancePovider

import com.google.common.cache.CacheBuilder; //導入方法依賴的package包/類
public CachedScriptClassInstancePovider(Engine engine, Function<String, S> createScriptFunction, String format,
        BiFunction<S, Class<T>, T> createInstanceFunction) {
    this.createScriptFunction = createScriptFunction;
    this.format = format;
    this.createInstanceFunction = createInstanceFunction;

    long cacheExpireTime = engine.getDefaultParameters().getScriptClassInstancePoviderCacheExpireTime();
    if (cacheExpireTime >= 0) {
        // Turn on the cache.
        CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder();
        if (cacheExpireTime > 0) {
            builder.expireAfterAccess(cacheExpireTime, TimeUnit.MILLISECONDS);
        }

        cache = builder.build(new CacheLoader<String, S>() {

            @Override
            public S load(String className) throws Exception {
                return createScript(className);
            }
        });
    }
}
 
開發者ID:softelnet,項目名稱:sponge,代碼行數:24,代碼來源:CachedScriptClassInstancePovider.java

示例4: MessageSlicer

import com.google.common.cache.CacheBuilder; //導入方法依賴的package包/類
private MessageSlicer(final Builder builder) {
    this.fileBackedStreamFactory = builder.fileBackedStreamFactory;
    this.messageSliceSize = builder.messageSliceSize;
    this.maxSlicingTries = builder.maxSlicingTries;

    id = SLICER_ID_COUNTER.getAndIncrement();
    this.logContext = builder.logContext + "_slicer-id-" + id;

    CacheBuilder<Identifier, SlicedMessageState<ActorRef>> cacheBuilder =
            CacheBuilder.newBuilder().removalListener(notification -> stateRemoved(notification));
    if (builder.expireStateAfterInactivityDuration > 0) {
        cacheBuilder = cacheBuilder.expireAfterAccess(builder.expireStateAfterInactivityDuration,
                builder.expireStateAfterInactivityUnit);
    }
    stateCache = cacheBuilder.build();
}
 
開發者ID:hashsdn,項目名稱:hashsdn-controller,代碼行數:17,代碼來源:MessageSlicer.java

示例5: InMemoryTaskArtifactCache

import com.google.common.cache.CacheBuilder; //導入方法依賴的package包/類
private InMemoryTaskArtifactCache(CacheCapSizer cacheCapSizer) {
    this.cacheCapSizer = cacheCapSizer;
    final CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder()
            .maximumSize(cacheCapSizer.getNumberOfCaches() * 2);
    this.cache = cacheBuilder //X2 to factor in a child build (for example buildSrc)
            .build();
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:8,代碼來源:InMemoryTaskArtifactCache.java

示例6: 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

示例7: newCache

import com.google.common.cache.CacheBuilder; //導入方法依賴的package包/類
static <K, V, E extends Exception> LoadingCache<K, V> newCache(CacheBuilder<K, V> builder, ThrowingFunction<K, V, E> loader) {
    return builder.build(new CacheLoader<K, V>() {
        @Override
        public V load(K key) throws E {
            return loader.applyThrows(key);
        }
    });
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:9,代碼來源:CacheUtils.java

示例8: 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

示例9: 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

示例10: DatabaseCache

import com.google.common.cache.CacheBuilder; //導入方法依賴的package包/類
protected DatabaseCache(DatabaseCollection<K, V> collection, CacheBuilder<K, V> builder) {
    this.databaseCollection = collection;
    this.wrapped = builder.build(getLoader());
    this.load();
}
 
開發者ID:Superioz,項目名稱:MooProject,代碼行數:6,代碼來源:DatabaseCache.java


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