@Test public void recomputesIfSupplierHasNotUpdatedForTooLong() throws InterruptedException { AtomicLong clockCounter = new AtomicLong(); testSupplier = new CachedComposedSupplier<>(this::countingFunction, this::constantNumber, 5, () -> clockCounter.get()); for (int i = 0; i < 25; i++) { clockCounter.incrementAndGet(); testSupplier.get(); } assertThat(counter).isEqualTo(5); }
@Override public R get() { if (!Objects.equals(supplier.get().version(), lastSuppliedVersion) || lastComputedTime + maxTimeBetweenRecomputes < clock.getTimeMillis()) { recompute(); } return cached; }
CachedComposedSupplier implements Supplier<R> { @Override public R get() { if (!Objects.equals(supplier.get().version(), lastSuppliedVersion) || lastComputedTime + maxTimeBetweenRecomputes < clock.getTimeMillis()) { recompute(); } return cached; } }
CachedComposedSupplier implements Supplier<R> { @Override public R get() { if (!Objects.equals(supplier.get().version(), lastSuppliedVersion) || lastComputedTime + maxTimeBetweenRecomputes < clock.getTimeMillis()) { recompute(); } return cached; } CachedComposedSupplier(Function<T, R> function, Supplier<VersionedType<T>> supplier);  CachedComposedSupplier(Function<T, R> function, Supplier<VersionedType<T>> supplier,
            long maxTimeBetweenRecomputes, Clock clock); }
CachedComposedSupplier implements Supplier<R> { @Override public R get() { if (!Objects.equals(supplier.get().version(), lastSuppliedVersion) || lastComputedTime + maxTimeBetweenRecomputes < clock.getTimeMillis()) { recompute(); } return cached; } CachedComposedSupplier(Function<T, R> function, Supplier<VersionedType<T>> supplier);  CachedComposedSupplier(Function<T, R> function, Supplier<VersionedType<T>> supplier,
            long maxTimeBetweenRecomputes, Clock clock); @Override R get(); }
CachedComposedSupplier implements Supplier<R> { @Override public R get() { if (!Objects.equals(supplier.get().version(), lastSuppliedVersion) || lastComputedTime + maxTimeBetweenRecomputes < clock.getTimeMillis()) { recompute(); } return cached; } CachedComposedSupplier(Function<T, R> function, Supplier<VersionedType<T>> supplier);  CachedComposedSupplier(Function<T, R> function, Supplier<VersionedType<T>> supplier,
            long maxTimeBetweenRecomputes, Clock clock); @Override R get();  }