List of usage examples for com.google.common.cache CacheBuilder newBuilder
public static CacheBuilder<Object, Object> newBuilder()
From source file:org.sonar.core.review.ReviewDao.java
public ReviewDao(MyBatis mybatis) { this.mybatis = mybatis; this.cacheByResource = CacheBuilder.newBuilder().weakValues() .build(new CacheLoader<Long, Collection<ReviewDto>>() { @Override/*from w w w .j a va 2s . co m*/ public Collection<ReviewDto> load(Long resourceId) { return doSelectOpenByResourceId(resourceId); } }); }
From source file:org.geoserver.jdbcconfig.internal.JDBCCacheProvider.java
@Override public <K extends Serializable, V extends Serializable> Cache<K, V> getCache(String cacheName) { // Cache creation Cache<K, V> cache = CacheBuilder.newBuilder().softValues().concurrencyLevel(DEFAULT_CONCURRENCY_LEVEL) .expireAfterAccess(expirationMinutes, TimeUnit.MINUTES).maximumSize(maxEntries).build(); return cache; }
From source file:eu.codesketch.adam.rest.infrastructure.config.Application.java
@Bean public CacheManager cacheManager() { GuavaCacheManager manager = new GuavaCacheManager("nodes", "info", "containers"); CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES) .maximumSize(25);//from w ww. j a va 2 s . co m manager.setCacheBuilder(builder); return manager; }
From source file:com.facebook.buck.rules.keys.ReflectiveRuleKeyFactory.java
public ReflectiveRuleKeyFactory(int seed) { this.seed = seed; this.knownFields = CacheBuilder.newBuilder().build(new ReflectiveAlterKeyLoader()); this.knownRules = CacheBuilder.newBuilder().weakKeys().build(new CacheLoader<BuildRule, RULE_KEY>() { @Override/*from www .j a va2s.c om*/ public RULE_KEY load(BuildRule key) throws Exception { return newInstance(key).build(); } }); }
From source file:com.facebook.presto.hive.FileSystemCache.java
@Inject public FileSystemCache(HiveClientConfig hiveClientConfig) { cache = CacheBuilder.newBuilder() .expireAfterAccess(hiveClientConfig.getFileSystemCacheTtl().toMillis(), TimeUnit.MILLISECONDS) .build();/*from ww w . jav a 2 s. c o m*/ }
From source file:kr.debop4j.core.cache.HashMapCacheRepository.java
public HashMapCacheRepository(long validFor) { if (validFor > 0) setExpiry(validFor);// w w w.j a v a 2 s . c om CacheBuilder builder = CacheBuilder.newBuilder(); if (validFor > 0) builder.expireAfterAccess(validFor, TimeUnit.MINUTES); cache = builder.build(); }
From source file:org.janusgraph.graphdb.transaction.vertexcache.GuavaVertexCache.java
public GuavaVertexCache(final long maxCacheSize, final int concurrencyLevel, final int initialDirtySize) { volatileVertices = new NonBlockingHashMapLong<InternalVertex>(initialDirtySize); log.debug("Created dirty vertex map with initial size {}", initialDirtySize); cache = CacheBuilder.newBuilder().maximumSize(maxCacheSize).concurrencyLevel(concurrencyLevel) .removalListener(new RemovalListener<Long, InternalVertex>() { @Override// ww w . java2s .co m public void onRemoval(RemovalNotification<Long, InternalVertex> notification) { if (notification.getCause() == RemovalCause.EXPLICIT) { //Due to invalidation at the end assert volatileVertices.isEmpty(); return; } //Should only get evicted based on size constraint or replaced through add assert (notification.getCause() == RemovalCause.SIZE || notification.getCause() == RemovalCause.REPLACED) : "Cause: " + notification.getCause(); InternalVertex v = notification.getValue(); if (v.isModified()) { volatileVertices.putIfAbsent(notification.getKey(), v); } } }).build(); log.debug("Created vertex cache with max size {}", maxCacheSize); }
From source file:com.eclipsesource.connect.security.authentication.TokenAdminImpl.java
public TokenAdminImpl() { cache = CacheBuilder.newBuilder().build(new CacheLoader<String, User>() { @Override//from w w w . ja v a2 s . co m public User load(String token) throws Exception { User user = loadUser(token); if (user == null) { throw new IllegalStateException("Could not load user for token: " + token); } return user; } }); }
From source file:com.ning.metrics.collector.processing.db.InMemorySubscriptionCache.java
@Inject public InMemorySubscriptionCache(CollectorConfig config) { this.cacheExpiryTime = config.getSubscriptionCacheTimeout(); this.subscriptionByTopicCache = CacheBuilder.newBuilder().maximumSize(config.getMaxSubscriptionCacheCount()) .expireAfterAccess(cacheExpiryTime.getPeriod(), cacheExpiryTime.getUnit()).recordStats().build(); this.subscriptionByFeedCache = CacheBuilder.newBuilder().maximumSize(config.getMaxSubscriptionCacheCount()) .expireAfterAccess(cacheExpiryTime.getPeriod(), cacheExpiryTime.getUnit()).recordStats().build(); }
From source file:org.apache.distributedlog.logsegment.LogSegmentMetadataCache.java
public LogSegmentMetadataCache(DistributedLogConfiguration conf, Ticker ticker) { cache = CacheBuilder.newBuilder().concurrencyLevel(conf.getNumWorkerThreads()).initialCapacity(1024) .expireAfterAccess(conf.getLogSegmentCacheTTLMs(), TimeUnit.MILLISECONDS) .maximumSize(conf.getLogSegmentCacheMaxSize()).removalListener(this).ticker(ticker).recordStats() .build();//from ww w. j a v a 2 s . com this.isCacheEnabled = conf.isLogSegmentCacheEnabled(); logger.info("Log segment cache is enabled = {}", this.isCacheEnabled); }