public NetworkLocationCache(NetworkTopology networkTopology) { this.networkTopology = requireNonNull(networkTopology, "networkTopology is null"); this.cache = CacheBuilder.newBuilder() .expireAfterWrite(1, DAYS) .refreshAfterWrite(12, HOURS) .build(asyncReloading(CacheLoader.from(this::locate), executor)); this.negativeCache = CacheBuilder.newBuilder() .expireAfterWrite(NEGATIVE_CACHE_DURATION.toMillis(), MILLISECONDS) .build(); }
private static CacheBuilder<Object, Object> newCacheBuilder(OptionalLong expiresAfterWriteMillis, OptionalLong refreshMillis, long maximumSize) { CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder(); if (expiresAfterWriteMillis.isPresent()) { cacheBuilder = cacheBuilder.expireAfterWrite(expiresAfterWriteMillis.getAsLong(), MILLISECONDS); } if (refreshMillis.isPresent() && (!expiresAfterWriteMillis.isPresent() || expiresAfterWriteMillis.getAsLong() > refreshMillis.getAsLong())) { cacheBuilder = cacheBuilder.refreshAfterWrite(refreshMillis.getAsLong(), MILLISECONDS); } cacheBuilder = cacheBuilder.maximumSize(maximumSize); return cacheBuilder; } }
public TableNameCompleter(QueryRunner queryRunner) { this.queryRunner = requireNonNull(queryRunner, "queryRunner session was null!"); tableCache = CacheBuilder.newBuilder() .refreshAfterWrite(RELOAD_TIME_MINUTES, TimeUnit.MINUTES) .build(asyncReloading(CacheLoader.from(this::listTables), executor)); functionCache = CacheBuilder.newBuilder() .build(asyncReloading(CacheLoader.from(this::listFunctions), executor)); }
public MongoSession(TypeManager typeManager, MongoClient client, MongoClientConfig config) { this.typeManager = requireNonNull(typeManager, "typeManager is null"); this.client = requireNonNull(client, "client is null"); this.schemaCollection = config.getSchemaCollection(); this.cursorBatchSize = config.getCursorBatchSize(); this.implicitPrefix = config.getImplicitRowFieldPrefix(); this.tableCache = CacheBuilder.newBuilder() .expireAfterWrite(1, HOURS) // TODO: Configure .refreshAfterWrite(1, MINUTES) .build(CacheLoader.from(this::loadTableSchema)); }
return refreshAfterWrite(duration.toNanos(), TimeUnit.NANOSECONDS);
@GwtIncompatible // refreshAfterWrite public void testRefresh_setTwice() { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().refreshAfterWrite(3600, SECONDS); try { // even to the same value is not allowed builder.refreshAfterWrite(3600, SECONDS); fail(); } catch (IllegalStateException expected) { } }
@GwtIncompatible // java.time.Duration public void testRefresh_setTwice_duration() { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().refreshAfterWrite(java.time.Duration.ofSeconds(3600)); try { // even to the same value is not allowed builder.refreshAfterWrite(java.time.Duration.ofSeconds(3600)); fail(); } catch (IllegalStateException expected) { } }
@Inject public ThriftMetadata( DriftClient<PrestoThriftService> client, ThriftHeaderProvider thriftHeaderProvider, TypeManager typeManager, @ForMetadataRefresh Executor metadataRefreshExecutor) { this.client = requireNonNull(client, "client is null"); this.thriftHeaderProvider = requireNonNull(thriftHeaderProvider, "thriftHeaderProvider is null"); this.typeManager = requireNonNull(typeManager, "typeManager is null"); this.tableCache = CacheBuilder.newBuilder() .expireAfterWrite(EXPIRE_AFTER_WRITE.toMillis(), MILLISECONDS) .refreshAfterWrite(REFRESH_AFTER_WRITE.toMillis(), MILLISECONDS) .build(asyncReloading(CacheLoader.from(this::getTableMetadataInternal), metadataRefreshExecutor)); }
@GwtIncompatible // refreshAfterWrite public void testRefresh_zero() { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder(); try { builder.refreshAfterWrite(0, SECONDS); fail(); } catch (IllegalArgumentException expected) { } }
@GwtIncompatible // java.time.Duration public void testRefresh_zero_duration() { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder(); try { builder.refreshAfterWrite(java.time.Duration.ZERO); fail(); } catch (IllegalArgumentException expected) { } }
builder.refreshAfterWrite(refreshDuration, refreshTimeUnit);
public void testSetRefresh() { long duration = 42; TimeUnit unit = TimeUnit.SECONDS; LocalCache<Object, Object> map = makeLocalCache(createCacheBuilder().refreshAfterWrite(duration, unit)); assertEquals(unit.toNanos(duration), map.refreshNanos); }
@Inject public ElasticsearchClient(ElasticsearchTableDescriptionProvider descriptions, ElasticsearchConnectorConfig config) throws IOException { tableDescriptions = requireNonNull(descriptions, "description is null"); ElasticsearchConnectorConfig configuration = requireNonNull(config, "config is null"); requestTimeout = configuration.getRequestTimeout(); maxAttempts = configuration.getMaxRequestRetries(); maxRetryTime = configuration.getMaxRetryTime(); for (ElasticsearchTableDescription tableDescription : tableDescriptions.getAllTableDescriptions()) { if (!clients.containsKey(tableDescription.getClusterName())) { Settings settings = Settings.builder().put("cluster.name", tableDescription.getClusterName()).build(); TransportAddress address = new TransportAddress(InetAddress.getByName(tableDescription.getHost()), tableDescription.getPort()); TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(address); clients.put(tableDescription.getClusterName(), client); } } this.columnMetadataCache = CacheBuilder.newBuilder() .expireAfterWrite(30, MINUTES) .refreshAfterWrite(15, MINUTES) .maximumSize(500) .build(asyncReloading(CacheLoader.from(this::loadColumns), executor)); }
@GwtIncompatible // java.time.Duration public void testLargeDurations() { java.time.Duration threeHundredYears = java.time.Duration.ofDays(365 * 300); CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder(); try { builder.expireAfterWrite(threeHundredYears); fail(); } catch (ArithmeticException expected) { } try { builder.expireAfterAccess(threeHundredYears); fail(); } catch (ArithmeticException expected) { } try { builder.refreshAfterWrite(threeHundredYears); fail(); } catch (ArithmeticException expected) { } }
builder.refreshAfterWrite(refresh.duration, refresh.unit);
.recordStats() .ticker(ticker) .refreshAfterWrite(1, MILLISECONDS) .build(loader); Object key = new Object();
.recordStats() .ticker(ticker) .refreshAfterWrite(1, MILLISECONDS) .build(loader); Object key = new Object();
.recordStats() .ticker(ticker) .refreshAfterWrite(1, MILLISECONDS) .build(loader); Object key = new Object();
.recordStats() .ticker(ticker) .refreshAfterWrite(1, MILLISECONDS) .build(loader); Object key = new Object();
.recordStats() .ticker(ticker) .refreshAfterWrite(1, MILLISECONDS) .build(loader); Object key = new Object();