List of usage examples for com.google.common.cache CacheBuilder newBuilder
public static CacheBuilder<Object, Object> newBuilder()
From source file:ezbake.security.service.registration.ClientLookup.java
@Inject public ClientLookup(Properties properties, RegistrationManager regManager) throws AccumuloSecurityException, AccumuloException { appCache = CacheBuilder.newBuilder().concurrencyLevel(20).refreshAfterWrite(2, TimeUnit.MINUTES) .expireAfterWrite(10, TimeUnit.MINUTES).build(new RegistrationLoader(properties, regManager)); }
From source file:org.eclipse.emf.compare.ide.ui.internal.contentmergeviewer.util.DynamicObject.java
/** * // ww w . ja v a2 s . c om */ public DynamicObject(Object target) { fTarget = target; fTargetClass = target.getClass(); fFieldCache = CacheBuilder.newBuilder().maximumSize(16).build(new CacheLoader<String, Field>() { @Override public Field load(String key) throws Exception { return getField(fTargetClass, key); } }); fMethodCache = CacheBuilder.newBuilder().maximumSize(16).build(new CacheLoader<MethodKey, Method>() { @Override public Method load(MethodKey key) throws Exception { return getMethod(fTargetClass, key.methodName, key.parameterTypes); } }); }
From source file:edu.uci.ics.jung.visualization.layout.CachingLayout.java
public void clear() { this.locations = CacheBuilder.newBuilder().build(new CacheLoader<V, Point2D>() { public Point2D load(V vertex) { return new Point2D.Double(); }//from w ww .j a v a2 s . c om }); }
From source file:fathom.realm.CachingRealm.java
public void setup(Config config) { realmName = getClass().getSimpleName(); if (config.hasPath("name")) { realmName = config.getString("name"); }/*ww w.ja v a 2 s . c o m*/ // configure an expiring account cache if (config.hasPath("cacheTtl")) { cacheTtl = config.getInt("cacheTtl"); } if (config.hasPath("cacheMax")) { cacheMax = config.getInt("cacheMax"); } if (cacheTtl > 0 && cacheMax > 0) { accountCache = CacheBuilder.newBuilder().expireAfterAccess(cacheTtl, TimeUnit.MINUTES) .maximumSize(cacheMax).build(); } }
From source file:com.facebook.presto.rakam.cache.MemoryMappedOrcDataSourceFactory.java
@Inject public MemoryMappedOrcDataSourceFactory(CacheConfig config) { cache = CacheBuilder.newBuilder().maximumWeight(config.getDataSize().toBytes()) .weigher(new Weigher<FileRegion, Slice>() { @Override// w w w. j a v a 2s . c o m public int weigh(FileRegion key, Slice value) { return value.length(); } }).build(new CacheLoader<FileRegion, Slice>() { public Slice load(FileRegion key) throws IOException { if (!key.file.exists()) { throw new FileNotFoundException(key.file.toString()); } try (RandomAccessFile randomAccessFile = new RandomAccessFile(key.file, "r"); FileChannel channel = randomAccessFile.getChannel()) { MappedByteBuffer byteBuffer = channel.map(FileChannel.MapMode.READ_ONLY, key.position, key.length); return Slices.wrappedBuffer(byteBuffer); } } }); }
From source file:com.glaf.shiro.cache.guava.GuavaCache.java
public GuavaCache(int cacheSize, int expireMinutes) { this.cacheSize = cacheSize; this.expireMinutes = expireMinutes; cache = CacheBuilder.newBuilder().maximumSize(cacheSize).expireAfterAccess(expireMinutes, TimeUnit.MINUTES) .build();/* ww w . j av a 2 s.c om*/ }
From source file:com.facebook.buck.i18n.NumberFormatter.java
/** * Given a function which creates {@link NumberFormat} objects for a {@link Locale}, * returns a wrapper providing thread-safe access to the formatter for that locale. *//* www .j a v a 2 s .c o m*/ public NumberFormatter(final Function<Locale, NumberFormat> numberFormatCreator) { numberFormatCache = CacheBuilder.newBuilder().maximumSize(1000) .build(new CacheLoader<NumberFormatterCacheKey, NumberFormat>() { @Override public NumberFormat load(NumberFormatterCacheKey key) { return numberFormatCreator.apply(key.getLocale()); } }); }
From source file:org.lunifera.runtime.common.state.impl.DataState.java
protected void ensureCache() { if (cache == null) { cache = CacheBuilder.newBuilder().initialCapacity(250).weakValues().build(); } }
From source file:br.com.caelum.vraptor.cache.CacheStoreFactory.java
public <V, K> CacheStore<K, V> createCacheWrapper(int capacity) { Cache<K, V> guavaCache = CacheBuilder.newBuilder().maximumSize(capacity).build(); return new GuavaCacheWrapper<>(guavaCache); }
From source file:com.codebullets.sagalib.processing.ReflectionInvoker.java
/** * Generates a new instance of ReflectionInvoker. *///from w w w .ja va2s. c o m @Inject public ReflectionInvoker(final SagaAnalyzer analyzer) { methodInvokers = CacheBuilder.newBuilder().build(new MethodSearcher(analyzer.scanHandledMessageTypes())); }