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


Java CacheBuilder.newBuilder方法代碼示例

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


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

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

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

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

示例4: Builder

import com.google.common.cache.CacheBuilder; //導入方法依賴的package包/類
public Builder() {
    this.builder = CacheBuilder.newBuilder();
}
 
開發者ID:Superioz,項目名稱:MooProject,代碼行數:4,代碼來源:DatabaseCache.java

示例5: newBuilder

import com.google.common.cache.CacheBuilder; //導入方法依賴的package包/類
static <K, V> CacheBuilder<K, V> newBuilder() {
    return (CacheBuilder<K, V>) CacheBuilder.newBuilder();
}
 
開發者ID:OvercastNetwork,項目名稱:ProjectAres,代碼行數:4,代碼來源:CacheUtils.java

示例6: ScriptService

import com.google.common.cache.CacheBuilder; //導入方法依賴的package包/類
@Inject
public ScriptService(Settings settings, Environment env, Set<ScriptEngineService> scriptEngines,
                     ResourceWatcherService resourceWatcherService, ScriptContextRegistry scriptContextRegistry) throws IOException {
    super(settings);
    this.parseFieldMatcher = new ParseFieldMatcher(settings);
    if (Strings.hasLength(settings.get(DISABLE_DYNAMIC_SCRIPTING_SETTING))) {
        throw new IllegalArgumentException(DISABLE_DYNAMIC_SCRIPTING_SETTING + " is not a supported setting, replace with fine-grained script settings. \n" +
                "Dynamic scripts can be enabled for all languages and all operations by replacing `script.disable_dynamic: false` with `script.inline: on` and `script.indexed: on` in elasticsearch.yml");
    }

    this.scriptEngines = scriptEngines;
    this.scriptContextRegistry = scriptContextRegistry;
    int cacheMaxSize = settings.getAsInt(SCRIPT_CACHE_SIZE_SETTING, SCRIPT_CACHE_SIZE_DEFAULT);
    TimeValue cacheExpire = settings.getAsTime(SCRIPT_CACHE_EXPIRE_SETTING, null);
    logger.debug("using script cache with max_size [{}], expire [{}]", cacheMaxSize, cacheExpire);

    this.defaultLang = settings.get(DEFAULT_SCRIPTING_LANGUAGE_SETTING, DEFAULT_LANG);

    CacheBuilder cacheBuilder = CacheBuilder.newBuilder();
    if (cacheMaxSize >= 0) {
        cacheBuilder.maximumSize(cacheMaxSize);
    }
    if (cacheExpire != null) {
        cacheBuilder.expireAfterAccess(cacheExpire.nanos(), TimeUnit.NANOSECONDS);
    }
    this.cache = cacheBuilder.removalListener(new ScriptCacheRemovalListener()).build();

    ImmutableMap.Builder<String, ScriptEngineService> enginesByLangBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<String, ScriptEngineService> enginesByExtBuilder = ImmutableMap.builder();
    for (ScriptEngineService scriptEngine : scriptEngines) {
        for (String type : scriptEngine.types()) {
            enginesByLangBuilder.put(type, scriptEngine);
        }
        for (String ext : scriptEngine.extensions()) {
            enginesByExtBuilder.put(ext, scriptEngine);
        }
    }
    this.scriptEnginesByLang = enginesByLangBuilder.build();
    this.scriptEnginesByExt = enginesByExtBuilder.build();

    this.scriptModes = new ScriptModes(this.scriptEnginesByLang, scriptContextRegistry, settings);

    // add file watcher for static scripts
    scriptsDirectory = env.scriptsFile();
    if (logger.isTraceEnabled()) {
        logger.trace("Using scripts directory [{}] ", scriptsDirectory);
    }
    FileWatcher fileWatcher = new FileWatcher(scriptsDirectory);
    fileWatcher.addListener(new ScriptChangesListener());

    if (settings.getAsBoolean(SCRIPT_AUTO_RELOAD_ENABLED_SETTING, true)) {
        // automatic reload is enabled - register scripts
        resourceWatcherService.add(fileWatcher);
    } else {
        // automatic reload is disable just load scripts once
        fileWatcher.init();
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:59,代碼來源:ScriptService.java


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