/** Adds the maximum size and weight bounding settings. */ private void addMaximum() { if (isSet("policy.maximum.size")) { configuration.setMaximumSize(OptionalLong.of(merged.getLong("policy.maximum.size"))); } if (isSet("policy.maximum.weight")) { configuration.setMaximumWeight(OptionalLong.of(merged.getLong("policy.maximum.weight"))); } if (isSet("policy.maximum.weigher")) { configuration.setWeigherFactory(Optional.of( FactoryBuilder.factoryOf(merged.getString("policy.maximum.weigher")))); } }
@Override protected CaffeineConfiguration<Integer, Integer> getConfiguration() { CacheEntryRemovedListener<Integer, Integer> listener = events -> removedWeight.addAndGet(Iterables.getOnlyElement(events).getValue()); CaffeineConfiguration<Integer, Integer> configuration = new CaffeineConfiguration<>(); configuration.setMaximumWeight(OptionalLong.of(MAXIMUM)); configuration.setWeigherFactory(Optional.of(() -> (key, value) -> value)); CacheEntryListenerConfiguration<Integer, Integer> listenerConfiguration = new MutableCacheEntryListenerConfiguration<Integer, Integer>(() -> listener, /* filterFactory */ null, /* isOldValueRequired */ true, /* isSynchronous */ true); configuration.addCacheEntryListenerConfiguration(listenerConfiguration); configuration.setExecutorFactory(MoreExecutors::directExecutor); return configuration; }
/** Adds the maximum size and weight bounding settings. */ private void addMaximum() { if (isSet("policy.maximum.size")) { configuration.setMaximumSize(OptionalLong.of(merged.getLong("policy.maximum.size"))); } if (isSet("policy.maximum.weight")) { configuration.setMaximumWeight(OptionalLong.of(merged.getLong("policy.maximum.weight"))); } if (isSet("policy.maximum.weigher")) { configuration.setWeigherFactory(Optional.of( FactoryBuilder.factoryOf(merged.getString("policy.maximum.weigher")))); } }