List of usage examples for com.google.common.cache CacheBuilder newBuilder
public static CacheBuilder<Object, Object> newBuilder()
From source file:org.lilyproject.rest.RecordScannerMapBuilder.java
public static Cache<String, RecordScanner> createRecordScannerMap(int delay, TimeUnit unit) { return CacheBuilder.newBuilder().expireAfterAccess(delay, unit).build(); }
From source file:org.wso2.carbon.logging.appender.StreamDefinitionCache.java
private static void init() { if (streamIdLoadingCache != null) { return;/* w ww . j ava 2 s. c o m*/ } synchronized (StreamDefinitionCache.class) { if (streamIdLoadingCache != null) { return; } streamIdLoadingCache = CacheBuilder.newBuilder().maximumSize(1000) .expireAfterAccess(120, TimeUnit.MINUTES).build(new CacheLoader<String, StreamData>() { @Override public StreamData load(String tenantId) throws Exception { return new StreamData(tenantId, ""); } }); } }
From source file:org.wso2.carbon.logging.service.appender.StreamDefinitionCache.java
private static void init() { if (streamIdLoadingCache != null) { return;/*w w w . ja va 2s.c o m*/ } synchronized (StreamDefinitionCache.class) { if (streamIdLoadingCache != null) { return; } streamIdLoadingCache = CacheBuilder.newBuilder().maximumSize(1000) .expireAfterAccess(120, TimeUnit.MINUTES).build(new CacheLoader<String, StreamData>() { @Override public StreamData load(String tenantId) throws Exception { return new StreamData(tenantId, "", ""); } }); } }
From source file:org.apache.whirr.util.Utils.java
/** * converts a map to a loading cache.//from ww w . j a v a2 s . c o m */ public static <K, V> LoadingCache<K, V> convertMapToLoadingCache(Map<K, V> in) { return CacheBuilder.newBuilder().build(CacheLoader.from(Functions.forMap(in))); }
From source file:com.palantir.atlasdb.cleaner.CachingPuncherStore.java
public static CachingPuncherStore create(final PuncherStore puncherStore, long granularityMillis) { LoadingCache<Long, Long> timeMillisToTimestamp = CacheBuilder.newBuilder().maximumSize(CACHE_SIZE) .<Long, Long>build(new CacheLoader<Long, Long>() { @Override/*from w w w.ja v a 2s. c om*/ public Long load(Long timeMillis) throws Exception { return puncherStore.get(timeMillis); } }); return new CachingPuncherStore(puncherStore, timeMillisToTimestamp, granularityMillis); }
From source file:com.android.tools.idea.npw.template.IconLoader.java
public static LoadingCache<File, Optional<Icon>> createLoadingCache() { return CacheBuilder.newBuilder().build(new IconLoader()); }
From source file:ec.tstoolkit.utilities.GuavaCaches.java
@Nonnull public static <K, V> Cache<K, V> ttlCache(@Nonnull Duration duration) { return CacheBuilder.newBuilder().expireAfterWrite(duration.toNanos(), TimeUnit.NANOSECONDS).build(); }
From source file:org.caleydo.view.domino.api.model.typed.MappingCaches.java
/** * * @return a generic cache for creating a mapper *///w w w .ja v a 2s. co m public static LoadingCache<Pair<IDType, IDType>, IIDTypeMapper<Integer, Integer>> create() { return CacheBuilder.newBuilder().build(new MapperCache2()); }
From source file:com.lithium.flow.util.Caches.java
@Nonnull @SuppressWarnings("unchecked") public static <K, V> LoadingCache<K, V> build(@Nonnull CheckedFunction<K, V, Exception> function, @Nonnull UnaryOperator<CacheBuilder<K, V>> operator) { checkNotNull(function);/* w w w .ja va 2 s.c o m*/ checkNotNull(operator); return operator.apply((CacheBuilder<K, V>) CacheBuilder.newBuilder()).build(loader(function)); }
From source file:com.davidbracewell.cache.impl.GuavaCacheUtils.java
/** * Converts a CacheSpec into a CacheBuilder * * @param specification The specification * @param <K> The key type * @param <V> The value type * @return The CacheBuilder// w w w. ja v a 2 s . com */ public static <K, V> CacheBuilder<K, V> cacheBuilderFromSpec(CacheSpec<K, V> specification) { CacheBuilder cacheBuilder = CacheBuilder.newBuilder(); if (specification.getMaxSize() > 0) { cacheBuilder.maximumSize(specification.getMaxSize()); } if (specification.getConcurrencyLevel() > 0) { cacheBuilder.concurrencyLevel(specification.getMaxSize()); } if (specification.getInitialCapacity() > 0) { cacheBuilder.initialCapacity(specification.getInitialCapacity()); } if (specification.getExpiresAfterAccess() > 0) { cacheBuilder.expireAfterAccess(specification.getExpiresAfterAccess(), TimeUnit.MILLISECONDS); } if (specification.getExpiresAfterWrite() > 0) { cacheBuilder.expireAfterWrite(specification.getExpiresAfterWrite(), TimeUnit.MILLISECONDS); } if (specification.isWeakKeys()) { cacheBuilder.weakKeys(); } if (specification.isWeakValues()) { cacheBuilder.weakValues(); } return Cast.as(cacheBuilder); }