当前位置: 首页>>代码示例>>Java>>正文


Java CacheBuilder.expireAfterAccess方法代码示例

本文整理汇总了Java中com.google.common.cache.CacheBuilder.expireAfterAccess方法的典型用法代码示例。如果您正苦于以下问题:Java CacheBuilder.expireAfterAccess方法的具体用法?Java CacheBuilder.expireAfterAccess怎么用?Java CacheBuilder.expireAfterAccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.cache.CacheBuilder的用法示例。


在下文中一共展示了CacheBuilder.expireAfterAccess方法的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: 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

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

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

示例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.expireAfterAccess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。