/** * Constructs an instance initialised with the supplied settings. * * @param settings the settings to configure the instance with. */ public ExternalCacheSettingsBuilder(ExternalCacheSettings settings) { this.defaultTtl = requireNonNull(settings.getDefaultTtl()); this.entryCountHint = requireNonNull(settings.getEntryCountHint()); this.dataChangeRateHint = requireNonNull(settings.getDataChangeRateHint()); this.entryGrowthRateHint = requireNonNull(settings.getEntryGrowthRateHint()); }
/** * Returns a new {@link ExternalCacheSettings} instance configured using the supplied settings. * * @return a new {@link ExternalCacheSettings} instance configured using the supplied settings. */ public ExternalCacheSettings build() { return new ExternalCacheSettings( defaultTtl, entryCountHint, dataChangeRateHint, entryGrowthRateHint); }
public static Cache<String, IdentifiedData> buildDelegate(ExternalCacheSettings settings) { //noinspection OptionalGetWithoutIsPresent return CacheBuilder.newBuilder() .maximumSize(settings.getEntryCountHint().get()) .expireAfterWrite(settings.getDefaultTtl().get().toMillis(), TimeUnit.MILLISECONDS) .build(); } }
@Test public void directExternalCache_normal_marshalling() { final ExternalCacheSettings settings = new ExternalCacheSettingsBuilder() .defaultTtl(Duration.ofSeconds(60)) .entryGrowthRateHint(ChangeRate.LOW_CHANGE) .dataChangeRateHint(ChangeRate.LOW_CHANGE) .entryCountHint(100) .build(); final DirectExternalCache<String> cache = vCacheFactory().getDirectExternalCache( "my-direct-cache", StringMarshalling.pair(), settings); assertThat(cache, notNullValue()); assertThat(cache.getName(), is("my-direct-cache")); final CompletionStage<Void> rmall = cache.removeAll(); assertThat(rmall, successful()); final CompletionStage<Boolean> put1 = cache.put("one", "eine", PUT_ALWAYS); assertThat(put1, successfulWith(is(true))); final CompletionStage<Optional<String>> get1 = cache.get("one"); assertThat(get1, successfulWith(is(Optional.of("eine")))); assertThat(vCacheManagement().allJvmCacheDetails().size(), is(0)); assertThat(vCacheManagement().allRequestCacheDetails().size(), is(0)); final Map<String, ExternalCacheDetails> allCacheDetails = vCacheManagement().allExternalCacheDetails(); assertThat(allCacheDetails, notNullValue()); assertThat(allCacheDetails.keySet(), containsInAnyOrder("my-direct-cache")); final ExternalCacheDetails cacheDetails = allCacheDetails.get("my-direct-cache"); assertThat(cacheDetails.getName(), is("my-direct-cache")); assertThat(cacheDetails.getSettings().getDefaultTtl(), is(Optional.of(MAX_TTL))); assertThat(cacheDetails.getSettings().getEntryCountHint(), is(Optional.of(MAX_ENTRIES))); assertThat(invocationsOfBegunTxns, is(0)); }
/** * Returns a new {@link ExternalCacheSettings} instance where the current settings * are overridden with settings specified in <tt>overrides</tt>. * * @param overrides contains the settings to override * @return a new {@link ExternalCacheSettings} instance with the <tt>overrides</tt> settings applied. */ public ExternalCacheSettings override(ExternalCacheSettings overrides) { return new ExternalCacheSettings( ifPresent(overrides.getDefaultTtl(), getDefaultTtl()), ifPresent(overrides.getEntryCountHint(), getEntryCountHint()), ifPresent(overrides.getDataChangeRateHint(), getDataChangeRateHint()), ifPresent(overrides.getEntryGrowthRateHint(), getEntryGrowthRateHint())); }