List of usage examples for com.google.common.cache CacheBuilder build
public <K1 extends K, V1 extends V> Cache<K1, V1> build()
From source file:org.apache.hadoop.io.file.tfile.CacheManager.java
public static final Cache<String, BlockReader> buildCache(CacheBuilder builder) { if (singleCache != null) { singleCache.cleanUp();/*from w w w . j a v a2s. com*/ } if (enableStats) { //todo: when we upgrade to a newer guava version we can use this // builder.recordStats(); } singleCache = builder.build(); return singleCache; }
From source file:ratpack.session.SessionModule.java
/** * A builder for an alternative cache for the default in memory store. * <p>/*from w w w. ja v a 2 s . c om*/ * This method can be used from within a custom {@link Module}. * <pre class="java">{@code * import com.google.inject.AbstractModule; * import ratpack.session.SessionModule; * * public class CustomSessionModule extends AbstractModule { * protected void configure() { * SessionModule.memoryStore(binder(), c -> c.maximumSize(100)); * } * } * }</pre> * }<p> * This method binds the built cache with the {@link #LOCAL_MEMORY_SESSION_CACHE_BINDING_KEY} key. * It also implicitly registers a {@link RemovalListener}, that releases the byte buffers as they are discarded. * * @param binder the guice binder * @param config the cache configuration */ public static void memoryStore(Binder binder, Consumer<? super CacheBuilder<AsciiString, ByteBuf>> config) { binder.bind(LOCAL_MEMORY_SESSION_CACHE_BINDING_KEY).toProvider(() -> { CacheBuilder<AsciiString, ByteBuf> cacheBuilder = Types.cast(CacheBuilder.newBuilder()); cacheBuilder.removalListener(n -> n.getValue().release()); config.accept(cacheBuilder); return cacheBuilder.build(); }).in(Scopes.SINGLETON); }
From source file:com.googlecode.webutilities.filters.ResponseCacheFilter.java
private static Cache<String, CacheObject> buildCache(/*int reloadAfterAccess, */int reloadAfterWrite) { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().softValues(); // if(reloadAfterAccess > 0) // builder.expireAfterAccess(reloadAfterAccess, TimeUnit.SECONDS); if (reloadAfterWrite > 0) builder.expireAfterWrite(reloadAfterWrite, TimeUnit.SECONDS); return builder.build(); }
From source file:com.sri.ai.expresso.core.DefaultSymbol.java
private static Cache<Object, Symbol> newSymbolTable() { CacheBuilder<Object, Object> cb = CacheBuilder.newBuilder(); long maximumSize = ExpressoConfiguration.getGlobalSymbolTableMaximumSize(); // Note: a maximumSize of // < 0 means no size restrictions // = 0 means no cache // > 0 means maximum size of cache if (maximumSize >= 0L) { cb.maximumSize(maximumSize);//from ww w . j av a 2s . c o m } if (AICUtilConfiguration.isRecordCacheStatistics()) { cb.recordStats(); } Cache<Object, Symbol> result = cb.build(); return result; }
From source file:org.locationtech.geogig.storage.cache.SharedCache.java
@VisibleForTesting static SharedCache build(int L1capacity, long maxCacheSizeBytes) { checkArgument(L1capacity >= 0);/* www . jav a 2s. co m*/ checkArgument(maxCacheSizeBytes >= 0, "Cache size can't be < 0, 0 meaning no cache at all"); if (0L == maxCacheSizeBytes) { return NO_CACHE; } int initialCapacityCount = 1_000_000; int concurrencyLevel = 16; CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder(); cacheBuilder = cacheBuilder.maximumWeight(maxCacheSizeBytes); cacheBuilder.weigher(Impl.SizeTracker.WEIGHER); cacheBuilder.initialCapacity(initialCapacityCount); cacheBuilder.concurrencyLevel(concurrencyLevel); cacheBuilder.recordStats(); Impl.SizeTracker sizeTracker = new Impl.SizeTracker(); cacheBuilder.removalListener(sizeTracker); Cache<Key, byte[]> byteCache = cacheBuilder.build(); return new Impl(L1capacity, byteCache, sizeTracker); }
From source file:org.locationtech.geogig.storage.postgresql.PGCache.java
private static PGCache build(Integer initialCapacityCount, Integer concurrencyLevel2, Long maxWeightBytes, Optional<Integer> expireSeconds) { CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder(); cacheBuilder = cacheBuilder.maximumWeight(maxWeightBytes); cacheBuilder.weigher(weigher);/*from w w w . j ava 2 s . co m*/ if (expireSeconds.isPresent()) { long seconds = expireSeconds.get(); Preconditions.checkArgument(seconds > -1); cacheBuilder.expireAfterAccess(seconds, TimeUnit.SECONDS); } cacheBuilder.initialCapacity(initialCapacityCount); cacheBuilder.concurrencyLevel(concurrencyLevel2); cacheBuilder.recordStats(); SizeTracker sizeTracker = new SizeTracker(); cacheBuilder.removalListener(sizeTracker); Cache<ObjectId, byte[]> byteCache = cacheBuilder.build(); return new PGCache(byteCache, sizeTracker); }
From source file:org.objectfabric.GoogleCache.java
@SuppressWarnings("unchecked") public GoogleCache(CacheBuilder builder) { super(true, new GoogleCacheBackend(builder.build().asMap())); builder.removalListener(new RemovalListener() { @Override/*from w w w. j a v a2s. c o m*/ public void onRemoval(RemovalNotification notification) { onEviction(notification.getValue()); } }); }
From source file:com.google.gitiles.TimeCache.java
public TimeCache(CacheBuilder<Object, Object> builder) { this.cache = builder.build(); }
From source file:com.sri.ai.expresso.core.DefaultSyntaxLeaf.java
private static Cache<Object, SyntaxLeaf> newSymbolTable() { CacheBuilder<Object, Object> cb = CacheBuilder.newBuilder(); long maximumSize = ExpressoConfiguration.getGlobalSymbolTableMaximumSize(); // Note: a maximumSize of // < 0 means no size restrictions // = 0 means no cache // > 0 means maximum size of cache if (maximumSize >= 0L) { cb.maximumSize(maximumSize);/* w ww. ja va 2 s .co m*/ } if (AICUtilConfiguration.isRecordCacheStatistics()) { cb.recordStats(); } Cache<Object, SyntaxLeaf> result = cb.build(); return result; }
From source file:net.maritimecloud.mms.server.rest.TailLogger.java
public TailLogger() { CacheBuilder<Object, Object> b = CacheBuilder.newBuilder(); b.expireAfterAccess(1, TimeUnit.HOURS); cache = b.build(); }