List of usage examples for com.google.common.cache CacheBuilder newBuilder
public static CacheBuilder<Object, Object> newBuilder()
From source file:com.thoughtworks.go.server.service.AuthorizationExtensionCacheService.java
public AuthorizationExtensionCacheService(AuthorizationExtension authorizationExtension, Ticker ticker) { this.authorizationExtension = authorizationExtension; isValidUserCache = CacheBuilder.newBuilder().ticker(ticker) .expireAfterWrite(CACHE_EXPIRY_IN_MINUTES, TimeUnit.MINUTES).build(); getUserRolesCache = CacheBuilder.newBuilder().ticker(ticker) .expireAfterWrite(CACHE_EXPIRY_IN_MINUTES, TimeUnit.MINUTES).build(); this.cacheKeyGenerator = new CacheKeyGenerator(getClass()); }
From source file:org.cloudifysource.rest.events.LogEntryMatcherProvider.java
public LogEntryMatcherProvider() { this.matcherCache = CacheBuilder.newBuilder() .build(new CacheLoader<LogEntryMatcherProviderKey, ContinuousLogEntryMatcher>() { @Override/*from w w w .j a v a 2 s .c o m*/ public ContinuousLogEntryMatcher load(final LogEntryMatcherProviderKey key) throws Exception { logger.fine( EventsUtils.getThreadId() + "Loading matcher cache with matcher for key " + key); // continuousMatcher is always the one with the USM event logger prefix. LogEntryMatcher continuousMatcher = EventsUtils.createUSMEventLoggerMatcher(); LogEntryMatcher initialMatcher = EventsUtils.createUSMEventLoggerMatcher(); return new ContinuousLogEntryMatcher(initialMatcher, continuousMatcher); } }); }
From source file:org.locationtech.geogig.model.internal.TreeCache.java
public TreeCache(final ObjectStore store) { this.store = store; final CacheLoader<Integer, RevTree> loader = new CacheLoader<Integer, RevTree>() { @Override//from www . j a va 2 s. co m public RevTree load(Integer key) throws Exception { ObjectId treeId = oidMapping.get(key); Preconditions.checkState(treeId != null, "No tree id mapped to " + key); RevTree tree = TreeCache.this.store.getTree(treeId); return tree; } }; this.cache = CacheBuilder.newBuilder().concurrencyLevel(1).maximumSize(100_000).build(loader); }
From source file:com.pingcap.tikv.RegionManager.java
public RegionManager(ReadOnlyPDClient pdClient) { this.pdClient = pdClient; regionCache = CacheBuilder.newBuilder().maximumSize(MAX_CACHE_CAPACITY) .build(new CacheLoader<Long, Future<Region>>() { public Future load(Long key) { return pdClient.getRegionByIDAsync(key); }// ww w.j a va 2 s.co m }); storeCache = CacheBuilder.newBuilder().maximumSize(MAX_CACHE_CAPACITY) .build(new CacheLoader<Long, Future<Store>>() { public Future load(Long id) { return pdClient.getStoreAsync(id); } }); keyToRegionIdCache = TreeRangeMap.create(); }
From source file:org.geoserver.script.ScriptManager.java
public ScriptManager(GeoServerDataDirectory dataDir) { this.dataDir = dataDir; engineMgr = new ScriptEngineManager(); sessions = CacheBuilder.newBuilder().maximumSize(10).expireAfterAccess(10, TimeUnit.MINUTES).build(); }
From source file:com.facebook.buck.rules.keys.ContentAgnosticRuleKeyBuilderFactory.java
public ContentAgnosticRuleKeyBuilderFactory(int seed, SourcePathResolver pathResolver) { super(seed);// w ww . jav a 2 s . com // Build the cache around the sub-rule-keys and their dep lists. ruleKeyCache = CacheBuilder.newBuilder().weakKeys().build(new CacheLoader<RuleKeyAppendable, RuleKey>() { @Override public RuleKey load(@Nonnull RuleKeyAppendable appendable) throws Exception { RuleKeyBuilder<RuleKey> subKeyBuilder = newBuilder(); appendable.appendToRuleKey(subKeyBuilder); return subKeyBuilder.build(); } }); this.pathResolver = pathResolver; this.fileHashLoader = new FileHashLoader() { @Override public HashCode get(Path path) throws IOException { return HashCode.fromLong(0); } @Override public long getSize(Path path) throws IOException { return 0; } @Override public HashCode get(ArchiveMemberPath archiveMemberPath) throws IOException { throw new AssertionError(); } }; }
From source file:com.facebook.buck.distributed.DistBuildCachingEngineDelegate.java
public DistBuildCachingEngineDelegate(SourcePathResolver sourcePathResolver, SourcePathRuleFinder ruleFinder, final DistBuildState remoteState, final LoadingCache<ProjectFilesystem, ? extends FileHashLoader> fileHashLoaders) { this.fileHashCacheLoader = CacheBuilder.newBuilder() .build(new CacheLoader<ProjectFilesystem, FileHashCache>() { @Override// w w w .j a va 2 s .co m public FileHashCache load(@Nonnull ProjectFilesystem filesystem) { return remoteState.createRemoteFileHashCache(filesystem); } }); ruleKeyFactories = DistBuildFileHashes.createRuleKeyFactories(sourcePathResolver, ruleFinder, fileHashLoaders, /* keySeed */ 0); }
From source file:org.trimou.prettytime.PrettyTimeHelper.java
/** * * @param prettyTimeFactory//w w w . j a va2 s.c o m */ public PrettyTimeHelper(final PrettyTimeFactory prettyTimeFactory) { this.prettyTimeCache = CacheBuilder.newBuilder().maximumSize(10) .build(new CacheLoader<Locale, PrettyTime>() { @Override public PrettyTime load(Locale locale) throws Exception { return prettyTimeFactory.createPrettyTime(locale); } }); }
From source file:com.datatorrent.lib.database.CacheStore.java
public CacheStore(CacheProperties properties) { Preconditions.checkNotNull(properties.entryExpiryStrategy, "expiryType"); CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder(); if (properties.entryExpiryStrategy == ExpiryType.EXPIRE_AFTER_ACCESS) { cacheBuilder.expireAfterAccess(properties.entryExpiryDurationInMillis, TimeUnit.MILLISECONDS); } else if (properties.entryExpiryStrategy == ExpiryType.EXPIRE_AFTER_WRITE) { cacheBuilder.expireAfterWrite(properties.entryExpiryDurationInMillis, TimeUnit.MILLISECONDS); }/* w ww . ja v a 2 s. co m*/ cache = cacheBuilder.build(); this.cleanupScheduler = Executors.newScheduledThreadPool(1); cleanupScheduler.scheduleAtFixedRate(new Runnable() { @Override public void run() { cache.cleanUp(); } }, properties.cacheCleanupIntervalInMillis, properties.cacheCleanupIntervalInMillis, TimeUnit.MILLISECONDS); }
From source file:com.cilogi.openweathermap.relay.RelayServlet.java
@Inject public RelayServlet(@UserAgent String userAgent) { this.userAgent = userAgent; cache = MemcacheServiceFactory.getMemcacheService(); fetch = URLFetchServiceFactory.getURLFetchService(); urlCache = CacheBuilder.newBuilder().concurrencyLevel(20).maximumSize(1000) .expireAfterWrite(300L, TimeUnit.SECONDS).build(new CacheLoader<String, byte[]>() { public byte[] load(String fullUrl) throws IOException { try { return loadUrl(fullUrl); } catch (IOException e) { LOG.warn("Can't load URL " + fullUrl + ": " + e.getMessage()); throw e; }//from w w w . j a v a 2 s . c o m } }); }