List of usage examples for com.google.common.cache CacheBuilder newBuilder
public static CacheBuilder<Object, Object> newBuilder()
From source file:uk.co.jwlawson.jcluster.pool.multiway.QuiverMatrixResourceLoader.java
private LoadingCache<QuiverKey<T>, Constructor<T>> getConstructorCache() { return CacheBuilder.newBuilder().maximumSize(10).build(new CacheLoader<QuiverKey<T>, Constructor<T>>() { @Override/*from w w w. j av a 2s . c om*/ public Constructor<T> load(QuiverKey<T> key) throws Exception { Class<T> clazz = key.getClassObject(); Constructor<T> constructor; try { constructor = clazz.getConstructor(Integer.TYPE, Integer.TYPE); } catch (NoSuchMethodException e) { throw new RuntimeException("No constructor found for class " + clazz, e); } catch (SecurityException e) { throw new RuntimeException("Cannot access constructor for class " + clazz, e); } return constructor; } }); }
From source file:org.gradle.api.internal.plugins.DefaultAppliedPlugins.java
public DefaultAppliedPlugins(AppliedPluginContainer container, PluginRegistry pluginRegistry) { this.container = container; idLookupCache = CacheBuilder.newBuilder().build(new PluginIdLookupCacheLoader(pluginRegistry)); }
From source file:pzalejko.iot.hardware.home.core.service.led.DefaultLedService.java
@PostConstruct public void init() { // @formatter:off cache = CacheBuilder.newBuilder().maximumSize(CACHE_SIZE) .removalListener((RemovalListener<Integer, Led>) (notification) -> notification.getValue().close()) .build(new InternalLedCacheLoader()); // @formatter:on }
From source file:org.cache2k.benchmark.thirdparty.GuavaCacheFactory.java
@Override public BenchmarkCache<Integer, Integer> create(int _maxElements) { MyBenchmarkCacheAdapter c = new MyBenchmarkCacheAdapter(); c.size = _maxElements;//w w w . j a va 2s . c o m CacheBuilder cb = CacheBuilder.newBuilder().maximumSize(_maxElements); if (withExpiry) { cb.expireAfterWrite(5 * 60, TimeUnit.SECONDS); } c.cache = cb.build(); return c; }
From source file:tech.beshu.ror.acl.definitions.groupsproviders.CachedGroupsProviderServiceClient.java
private CachedGroupsProviderServiceClient(GroupsProviderServiceClient underlying, Duration ttl) { this.underlying = underlying; this.cache = CacheBuilder.newBuilder().expireAfterWrite(ttl.toMillis(), TimeUnit.MILLISECONDS).build(); }
From source file:org.openehr.designer.util.CachedLockProvider.java
public CachedLockProvider() { lockCache = CacheBuilder.newBuilder().weakValues().build(new CacheLoader<K, Lock>() { @Override//from w ww.ja va 2 s .c o m public Lock load(K key) throws Exception { return new ReentrantLock(); } }); }
From source file:com.enitalk.configs.BotConfig.java
@Bean @Primary// w ww . j a va2s. com public LoadingCache<String, String> tokenCache() { LoadingCache<String, String> cache = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.DAYS) .build(new CacheLoader<String, String>() { @Override public String load(String key) throws Exception { String id = jackson.createObjectNode().put("login", env.getProperty("bot.login")) .put("password", env.getProperty("bot.pass")).toString(); byte[] auth = Request.Post(env.getProperty("bot.auth")) .bodyString(id, ContentType.APPLICATION_JSON).execute().returnContent().asBytes(); JsonNode tree = jackson.readTree(auth); logger.info("Bot token came {}", tree); String authToken = tree.path("token").asText(); return authToken; } }); return cache; }
From source file:org.wso2.carbon.appfactory.git.UserPasswordCache.java
public UserPasswordCache(GitBlitConfiguration configuration) { int cacheExpiryTime = Integer .parseInt(configuration.getProperty(GitBlitConstants.APPFACTORY_CACHE_EXPIRY_TIME, "1")); cache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(cacheExpiryTime, TimeUnit.MINUTES) .build();/*from ww w . j ava 2 s .c om*/ }
From source file:it.sayservice.platform.smartplanner.otp.OTPCache.java
public OTPCache() { cache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterAccess(24, TimeUnit.HOURS) .build(new CacheLoader<String, ExtendedTransitTimeTable>() { @Override/*from w w w .j av a 2 s .co m*/ public ExtendedTransitTimeTable load(String key) throws Exception { String pars[] = keyToParams(key); ExtendedTransitTimeTable ett = manager.buildTransitSchedule(pars[0], pars[1], pars[2], Long.parseLong(pars[3]), Long.parseLong(pars[4]), TransitScheduleResults.ALL, true, true); return ett; } }); }
From source file:de.ks.imagecache.Images.java
private Images() { loader = new ImageLoader(); cache = CacheBuilder.newBuilder()// .initialCapacity(300)// .softValues()// .build(loader);/*from ww w . j a va2s.c om*/ }