List of usage examples for com.google.common.cache CacheBuilder newBuilder
public static CacheBuilder<Object, Object> newBuilder()
From source file:co.cask.cdap.metrics.collect.AggregatedMetricsEmitter.java
AggregatedMetricsEmitter(String context, String runId, String name) { this.context = context; this.runId = runId; this.name = name; this.value = new AtomicInteger(); this.tagValues = CacheBuilder.newBuilder().expireAfterAccess(CACHE_EXPIRE_MINUTES, TimeUnit.MINUTES) .build(new CacheLoader<String, AtomicInteger>() { @Override/*from w w w . j ava2 s . com*/ public AtomicInteger load(String key) throws Exception { return new AtomicInteger(); } }); if (name == null || name.isEmpty()) { LOG.warn("Creating emmitter with " + (name == null ? "null" : "empty") + " name, " + "for context " + context + " and runId " + runId); } }
From source file:org.pac4j.http.credentials.authenticator.LocalCachingAuthenticator.java
public LocalCachingAuthenticator(final Authenticator<T> delegate, final long cacheSize, final long timeout, final TimeUnit timeUnit) { this.cacheLoader = new UserProfileCacheLoader<>(delegate); this.cache = CacheBuilder.newBuilder().maximumSize(cacheSize).expireAfterWrite(timeout, timeUnit) .build(this.cacheLoader); }
From source file:rapture.postgres.PostgresFactory.java
private PostgresFactory() { connectionCache = CacheBuilder.newBuilder().maximumSize(10) .build(new ConnectionCacheLoader(new DataSourceMonitor())); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override/*ww w .j a va 2 s . co m*/ public void run() { for (Map.Entry<String, ConnectionInfo> entry : connectionCache.asMap().entrySet()) { DataSource ds = entry.getValue().getDataSource(); if (ds != null && ds instanceof PooledDataSource) { PooledDataSource pds = (PooledDataSource) ds; try { pds.close(); } catch (SQLException e) { log.error(ExceptionToString.format(e)); } } } } })); }
From source file:org.jboss.hal.meta.description.ResourceDescriptionRegistry.java
@Inject public ResourceDescriptionRegistry(StatementContext statementContext, Environment environment) { super(new ResourceDescriptionStatementContext(statementContext, environment), RESOURCE_DESCRIPTION_TYPE); this.cache = CacheBuilder .newBuilder().maximumSize(CACHE_SIZE).recordStats().removalListener(notification -> logger .debug("Remove {} from {} cache: {}", notification.getKey(), type, notification.getCause())) .build();//from w w w . ja v a 2 s .c o m this.templateProcessor = new ResourceDescriptionTemplateProcessor(); }
From source file:com.siemens.sw360.portal.users.UserCache.java
public UserCache() { // Initialize user loader UserLoader loader = new UserLoader(); List<User> allUsers;//from www. ja v a 2s . c o m try { allUsers = loader.getAllUsers(); } catch (TException ignored) { allUsers = Collections.emptyList(); } // Initialize user cache cache = CacheBuilder.newBuilder().maximumSize(allUsers.size() + 100).expireAfterWrite(1, TimeUnit.DAYS) .build(loader); if (allUsers.size() > 0) { cache.putAll(Maps.uniqueIndex(allUsers, new Function<User, String>() { @Override public String apply(User input) { return input.getEmail(); } })); } }
From source file:springfox.documentation.schema.property.CachingModelPropertiesProvider.java
@Autowired public CachingModelPropertiesProvider(final TypeResolver resolver, @Qualifier("optimized") final ModelPropertiesProvider delegate) { cache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(24, TimeUnit.HOURS) .build(new CacheLoader<ModelContext, List<ModelProperty>>() { public List<ModelProperty> load(ModelContext key) { return delegate.propertiesFor(key.resolvedType(resolver), key); }//from www . ja va2s. co m }); }
From source file:com.kixeye.kixmpp.server.cluster.mapreduce.MapReduceTracker.java
public MapReduceTracker(KixmppServer server, ScheduledExecutorService scheduledExecutorService) { this.server = server; this.requests = CacheBuilder.newBuilder().expireAfterWrite(15, TimeUnit.SECONDS).removalListener(this) .build();/*from ww w . j a v a2 s. c o m*/ // periodically call cache clean up expiration callbacks scheduledExecutorService.scheduleWithFixedDelay(new Runnable() { @Override public void run() { requests.cleanUp(); } }, 10, 10, TimeUnit.SECONDS); }
From source file:org.apache.usergrid.security.shiro.utils.LocalShiroCache.java
public LocalShiroCache() { // set a smaller ttl long ttl = 1; int configuredMaxSize; try {// w w w. j a v a 2s . c o m ttl = Integer.parseInt(System.getProperty(CACHE_TTL_PROP)); } catch (NumberFormatException e) { // already defaulted to 1 above } try { configuredMaxSize = Integer.parseInt(System.getProperty(CACHE_MAX_SIZE_PROP)); } catch (NumberFormatException e) { configuredMaxSize = 1000; } this.cache = CacheBuilder.newBuilder().maximumSize(Math.min(1000, configuredMaxSize)) .expireAfterWrite(ttl, TimeUnit.SECONDS).build(); }
From source file:com.strandls.alchemy.rest.client.RestInterfaceAnalyzer.java
/** * Creates a new instance./*from www. j a va2 s .c o m*/ */ public RestInterfaceAnalyzer() { metadataCache = CacheBuilder.newBuilder().build(new CacheLoader<Class<?>, RestInterfaceMetadata>() { @Override public RestInterfaceMetadata load(final Class<?> klass) throws Exception { return doAnalyze(klass); } }); }
From source file:love.sola.netsupport.session.MapSessionRepository.java
public MapSessionRepository() { this(CacheBuilder.newBuilder().concurrencyLevel(4).maximumSize(65535) .expireAfterAccess(Settings.I.User_Session_Max_Inactive, TimeUnit.SECONDS) .build(new CacheLoader<String, MapSession>() { @Override/*from ww w .j a va 2s. c om*/ public MapSession load(@Nonnull String key) throws Exception { return new MapSession(key); } })); }