public InstanceConfigAuditUtil(final InstanceService instanceService) { this.instanceService = instanceService; auditExecutorService = Executors.newSingleThreadExecutor( ApolloThreadFactory.create("InstanceConfigAuditUtil", true)); auditStopped = new AtomicBoolean(false); instanceCache = CacheBuilder.newBuilder().expireAfterAccess(1, TimeUnit.HOURS) .maximumSize(INSTANCE_CACHE_MAX_SIZE).build(); instanceConfigReleaseKeyCache = CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.DAYS) .maximumSize(INSTANCE_CONFIG_CACHE_MAX_SIZE).build(); }
/** * Creates a new instance of {@link UfsSyncPathCache}. */ public UfsSyncPathCache() { mCache = CacheBuilder.newBuilder().maximumSize(MAX_PATHS).build(); }
public void testMaximumSize_setTwice() { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().maximumSize(16); try { // even to the same value is not allowed builder.maximumSize(16); fail(); } catch (IllegalStateException expected) { } }
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; } }
/** Returns an iterable containing all combinations of maximumSize and expireAfterAccess/Write. */ @SuppressWarnings("unchecked") // varargs static Iterable<CacheBuilder<Object, Object>> allEvictingMakers() { return ImmutableList.of( createCacheBuilder().maximumSize(SMALL_MAX_SIZE), createCacheBuilder().expireAfterAccess(99999, SECONDS), createCacheBuilder().expireAfterWrite(99999, SECONDS), createCacheBuilder() .maximumSize(SMALL_MAX_SIZE) .expireAfterAccess(SMALL_MAX_SIZE, TimeUnit.SECONDS), createCacheBuilder() .maximumSize(SMALL_MAX_SIZE) .expireAfterWrite(SMALL_MAX_SIZE, TimeUnit.SECONDS)); }
public TableConfigCache(ZkHelixPropertyStore<ZNRecord> propertyStore) { _tableConfigCache = CacheBuilder.newBuilder().maximumSize(DEFAULT_CACHE_SIZE) .expireAfterWrite(DEFAULT_CACHE_TIMEOUT_IN_MINUTE, TimeUnit.MINUTES) .build(new CacheLoader<String, TableConfig>() { @Override public TableConfig load(String tableNameWithType) throws Exception { return ZKMetadataProvider.getTableConfig(_propertyStore, tableNameWithType); } }); _propertyStore = propertyStore; }
/** * Creates a new instance of {@link UfsBlockLocationCache}. * * @param mountTable the mount table */ public LazyUfsBlockLocationCache(MountTable mountTable) { mCache = CacheBuilder.newBuilder().maximumSize(MAX_BLOCKS).build(); mMountTable = mountTable; }
CacheBuilder<K, V> recreateCacheBuilder() { CacheBuilder<K, V> builder = CacheBuilder.newBuilder() .setKeyStrength(keyStrength) .setValueStrength(valueStrength) builder.strictParsing = false; if (expireAfterWriteNanos > 0) { builder.expireAfterWrite(expireAfterWriteNanos, TimeUnit.NANOSECONDS); builder.maximumSize(maxWeight);
public void testMaximumSize_negative() { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder(); try { builder.maximumSize(-1); fail(); } catch (IllegalArgumentException expected) { } }
/** * Returns an iterable containing all combinations of maximumSize, expireAfterAccess/Write, * weakKeys and weak/softValues. */ @SuppressWarnings("unchecked") // varargs private static Iterable<CacheBuilder<Object, Object>> allEntryTypeMakers() { List<CacheBuilder<Object, Object>> result = newArrayList(allKeyValueStrengthMakers()); for (CacheBuilder<Object, Object> builder : allKeyValueStrengthMakers()) { result.add(builder.maximumSize(SMALL_MAX_SIZE)); } for (CacheBuilder<Object, Object> builder : allKeyValueStrengthMakers()) { result.add(builder.expireAfterAccess(99999, SECONDS)); } for (CacheBuilder<Object, Object> builder : allKeyValueStrengthMakers()) { result.add(builder.expireAfterWrite(99999, SECONDS)); } for (CacheBuilder<Object, Object> builder : allKeyValueStrengthMakers()) { result.add(builder.maximumSize(SMALL_MAX_SIZE).expireAfterAccess(99999, SECONDS)); } for (CacheBuilder<Object, Object> builder : allKeyValueStrengthMakers()) { result.add(builder.maximumSize(SMALL_MAX_SIZE).expireAfterWrite(99999, SECONDS)); } return result; }
private LoadingCache<String, JsonQuery> createQueryCache() { CacheLoader<String, JsonQuery> loader = new CacheLoader<String, JsonQuery>() { @Override public JsonQuery load(@Nonnull String query) throws JsonQueryException { return JsonQuery.compile(query); } }; return CacheBuilder.newBuilder().expireAfterWrite(1, TimeUnit.HOURS).maximumSize(1000).build(loader); } }
public SurfaceCache (int capacity) { this.cache = CacheBuilder.newBuilder() .maximumSize(100) .build(); }
CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder(); if (initialCapacity != null) { builder.initialCapacity(initialCapacity); builder.maximumSize(maximumSize); builder.expireAfterWrite(writeExpirationDuration, writeExpirationTimeUnit);
@GwtIncompatible // maximumWeight public void testMaximumSize_andWeight() { CacheBuilder<Object, Object> builder = CacheBuilder.newBuilder().maximumSize(16); try { builder.maximumWeight(16); fail(); } catch (IllegalStateException expected) { } }
.concurrencyLevel(1) .initialCapacity(1) .maximumSize(SMALL_MAX_SIZE) .expireAfterWrite(99999, SECONDS)); Segment<Object, Object> segment = map.segments[0]; AtomicReferenceArray<ReferenceEntry<Object, Object>> table = segment.table;
public TimerManager(long maxSize, int minutesUntilExpire) { contexts = CacheBuilder.newBuilder() .maximumSize(maxSize) .expireAfterWrite(minutesUntilExpire, TimeUnit.MINUTES) .build(); }
public CachingStatsSource(int cacheSize) { cache = CacheBuilder.newBuilder().maximumSize(cacheSize).build(); }
CacheBuilder<K, V> recreateCacheBuilder() { CacheBuilder<K, V> builder = CacheBuilder.newBuilder() .setKeyStrength(keyStrength) .setValueStrength(valueStrength) builder.strictParsing = false; if (expireAfterWriteNanos > 0) { builder.expireAfterWrite(expireAfterWriteNanos, TimeUnit.NANOSECONDS); builder.maximumSize(maxWeight);
@GwtIncompatible // weigher public void testWeigher_withMaximumSize() { try { CacheBuilder.newBuilder().weigher(constantWeigher(42)).maximumSize(1); fail(); } catch (IllegalStateException expected) { } try { CacheBuilder.newBuilder().maximumSize(1).weigher(constantWeigher(42)); fail(); } catch (IllegalStateException expected) { } }
.concurrencyLevel(1) .initialCapacity(1) .maximumSize(SMALL_MAX_SIZE) .expireAfterWrite(99999, SECONDS) .removalListener(listener)); Segment<Object, Object> segment = map.segments[0];