List of usage examples for com.google.common.cache CacheBuilder newBuilder
public static CacheBuilder<Object, Object> newBuilder()
From source file:com.hazelcast.client.GuavaNearCacheImpl.java
public GuavaNearCacheImpl(NearCacheConfig nc, final MapClientProxy<K, V> map) { this.map = map; CacheBuilder cacheBuilder = CacheBuilder.newBuilder().maximumSize(nc.getMaxSize()); if (nc.getTimeToLiveSeconds() > 0) cacheBuilder.expireAfterWrite(nc.getTimeToLiveSeconds(), TimeUnit.SECONDS); if (nc.getMaxIdleSeconds() > 0) cacheBuilder.expireAfterAccess(nc.getMaxIdleSeconds(), TimeUnit.SECONDS); cache = cacheBuilder.build(new CacheLoader() { @Override// w ww .ja v a2 s . c o m public Object load(Object o) throws Exception { try { return map.get0(o); } catch (Exception e) { throw new ExecutionException(e); } } }); }
From source file:com.boundlessgeo.geoserver.util.RecentObjectCache.java
public RecentObjectCache(final int size) { cache = CacheBuilder.newBuilder().build(new CacheLoader<Class<?>, EvictingQueue<Ref>>() { @Override//from www . j a v a 2 s. c om public EvictingQueue<Ref> load(Class<?> key) throws Exception { return EvictingQueue.create(size); } }); }
From source file:org.nuxeo.ecm.core.cache.InMemoryCacheImpl.java
public InMemoryCacheImpl(CacheDescriptor desc) { super(desc);/*from w w w. j av a2s . c o m*/ CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder(); builder = builder.expireAfterWrite(desc.ttl, TimeUnit.MINUTES); if (desc.options.containsKey("concurrencyLevel")) { builder = builder.concurrencyLevel(Integer.valueOf(desc.options.get("concurrencyLevel")).intValue()); } if (desc.options.containsKey("maxSize")) { builder = builder.maximumSize(Integer.valueOf(desc.options.get("maxSize")).intValue()); } cache = builder.build(); }
From source file:org.gradle.tooling.internal.provider.ClassLoaderCache.java
public ClassLoaderCache() { classLoaderDetails = CacheBuilder.newBuilder().weakKeys().build(); classLoaderIds = CacheBuilder.newBuilder().softValues().build(); }
From source file:com.coredot.jdebugconsole.TimeStat.java
public TimeStat(String name, int seconds) { this.name = name; cache = new Cache( CacheBuilder.newBuilder().expireAfterWrite(seconds, TimeUnit.SECONDS).build(new RateCacheLoader())); }
From source file:edu.illinois.cs.cogcomp.wikifier.utils.concurrent.NamedLocks.java
/** * Constructs the lock holder./* ww w . jav a2s . com*/ */ public NamedLocks() { locks = CacheBuilder.newBuilder().weakValues().build(new CacheLoader<Object, Object>() { @Override public Object load(Object k) throws Exception { return new Object(); } }); }
From source file:org.onebusaway.nextbus.impl.gtfsrt.GtfsrtCache.java
@PostConstruct public void setup() { _cache = CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.SECONDS).build(); }
From source file:com.github.jknack.handlebars.io.GuavaCachedTemplateLoader.java
/** * Create a cached template loader that will expire entries if they are not * used after some time.//from w ww .jav a 2 s . c o m * @param delegate * to be decorated. * @param duration * never negative. * @param unit * never null. * @return never null. */ public static GuavaCachedTemplateLoader cacheWithExpiration(final TemplateLoader delegate, final long duration, final TimeUnit unit) { Cache<String, TemplateSource> cache = CacheBuilder.newBuilder().expireAfterAccess(duration, unit).build(); return new GuavaCachedTemplateLoader(delegate, cache); }
From source file:org.apache.usergrid.corepersistence.index.CollectionSettingsCache.java
@Inject public CollectionSettingsCache(CollectionSettingsCacheFig fig) { this.cache = CacheBuilder.newBuilder().maximumSize(fig.getCacheSize()) .expireAfterWrite(fig.getCacheTimeout(), TimeUnit.SECONDS).build(); }
From source file:org.pentaho.metastore.stores.xml.AutomaticXmlMetaStoreCache.java
@Override protected <K, V> Map<K, V> createStorage() { return CacheBuilder.newBuilder().softValues().<K, V>build().asMap(); }