Example usage for com.google.common.cache CacheBuilder newBuilder

List of usage examples for com.google.common.cache CacheBuilder newBuilder

Introduction

In this page you can find the example usage for com.google.common.cache CacheBuilder newBuilder.

Prototype

public static CacheBuilder<Object, Object> newBuilder() 

Source Link

Document

Constructs a new CacheBuilder instance with default settings, including strong keys, strong values, and no automatic eviction of any kind.

Usage

From source file:com.kolich.curacao.examples.components.SessionCacheImpl.java

public SessionCacheImpl() {
    cache_ = CacheBuilder.newBuilder().expireAfterAccess(30L, TimeUnit.MINUTES).build().asMap(); // Concurrent map
}

From source file:org.gradle.api.tasks.util.internal.CachingPatternSpecFactory.java

public CachingPatternSpecFactory() {
    specResultCache = CacheBuilder.newBuilder().maximumSize(RESULTS_CACHE_MAX_SIZE)
            .initialCapacity(RESULTS_CACHE_MAX_SIZE / 10).build();
    specInstanceCache = CacheBuilder.newBuilder().maximumSize(INSTANCES_MAX_SIZE)
            .initialCapacity(INSTANCES_MAX_SIZE / 10).build();
}

From source file:io.mandrel.script.ScriptingService.java

public ScriptingService() {
    ClassLoader classLoader = getClass().getClassLoader();

    sem = new ScriptEngineManager(classLoader);
    scripts = CacheBuilder.newBuilder().build();

    sem.getEngineFactories().stream().forEach(factory -> {
        log.debug("Engine : {}, version: {}, threading: {}", factory.getEngineName(),
                factory.getEngineVersion(), factory.getParameter("THREADING"));
    });//from   w  ww.  ja  va 2s  . c o m
}

From source file:com.linkedin.pinot.controller.helix.core.realtime.TableConfigCache.java

public TableConfigCache(ZkHelixPropertyStore<ZNRecord> propertyStore) {
    _tableConfigCache = CacheBuilder.newBuilder().maximumSize(DEFAULT_CACHE_SIZE)
            .expireAfterWrite(DEFAULT_CACHE_TIMEOUT_IN_MINUTE, TimeUnit.MINUTES)
            .build(new CacheLoader<String, TableConfig>() {
                @Override/*from w  ww. j  a va 2s. c o  m*/
                public TableConfig load(String tableNameWithType) throws Exception {
                    return ZKMetadataProvider.getTableConfig(_propertyStore, tableNameWithType);
                }
            });
    _propertyStore = propertyStore;
}

From source file:com.ibm.stocator.fs.cache.MemoryCache.java

private MemoryCache(int cacheSize) {
    LOG.debug("Guava initiated with size {} expiration 30 secods", cacheSize);
    fsCache = CacheBuilder.newBuilder().maximumSize(cacheSize).expireAfterWrite(30, TimeUnit.SECONDS).build();
}

From source file:io.atomix.core.election.impl.CachingAsyncLeaderElector.java

public CachingAsyncLeaderElector(AsyncLeaderElector<T> delegateLeaderElector, CacheConfig cacheConfig) {
    super(delegateLeaderElector);
    cache = CacheBuilder.newBuilder().maximumSize(cacheConfig.getSize())
            .build(CacheLoader.from(super::getLeadership));

    cacheUpdater = event -> {/*from   w w w.  java 2 s. c om*/
        Leadership<T> leadership = event.newLeadership();
        cache.put(event.topic(), CompletableFuture.completedFuture(leadership));
    };
    statusListener = status -> {
        if (status == PrimitiveState.SUSPENDED || status == PrimitiveState.CLOSED) {
            cache.invalidateAll();
        }
    };
    addListener(cacheUpdater);
    addStateChangeListener(statusListener);
}

From source file:io.confluent.kafka.connect.syslog.source.HostnameResolverImpl.java

public HostnameResolverImpl(BaseSyslogSourceConfig config) {
    this.config = config;
    reverseDnsCache = CacheBuilder.newBuilder()
            .expireAfterWrite(this.config.reverseDnsCacheTtl(), TimeUnit.MILLISECONDS).recordStats().build();
}

From source file:com.necla.simba.server.simbastore.cache.ChunkCache.java

public ChunkCache(int cacheSizeInMB) {

    long cacheMem = cacheSizeInMB * 1024 * 1024;
    cache = CacheBuilder.newBuilder().maximumSize(cacheMem / Preferences.MAX_FRAGMENT_SIZE).concurrencyLevel(16)
            .recordStats()// w  ww.  ja va2 s .  co  m
            // .maximumWeight(cacheMem)
            // .weigher(new Weigher<String, byte[]>() {
            // public int weigh(String key, byte[] value) {
            // return value.length;
            // }
            // })
            .build();

    // flush the print buffer every N seconds (N = 30)
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
            StringBuilder sb = new StringBuilder();
            sb.append("CHUNK_CACHE:");
            sb.append("\nhits=" + cache.stats().hitCount());
            sb.append("\nmisses=" + cache.stats().missCount());
            sb.append("\nload=" + cache.stats().loadCount());
            sb.append("\nevictions=" + cache.stats().evictionCount());
            sb.append("\nrequests=" + cache.stats().requestCount());
            System.out.println(sb.toString());
        }
    }, 0, 30000);

}

From source file:com.reachcall.pretty.config.Resolver.java

public Resolver(Configuration activeConfiguration, long expirationTime) {
    configurations = CacheBuilder.newBuilder().expireAfterAccess(expirationTime, TimeUnit.MILLISECONDS)
            .concurrencyLevel(128).recordStats().build();
    affinities = CacheBuilder.newBuilder().expireAfterAccess(expirationTime, TimeUnit.MILLISECONDS)
            .concurrencyLevel(128).recordStats().build();
    this.expirationTime = expirationTime;
}

From source file:com.isotrol.impe3.oi.impl.OIMemberComponent.java

/** Constructor. */
public OIMemberComponent() {
    final CacheLoader<Long, String> computer = new CacheLoader<Long, String>() {
        public String load(Long from) {
            return findById(OIMemberEntity.class, from).getMemberId();
        }/*from   w w  w  .j  a v  a2s.c o  m*/
    };
    cache = CacheBuilder.newBuilder().softValues().build(computer);
}