@Override public V reload(K key, V oldValue) { @SuppressWarnings("unchecked") V newValue = (V) loader.asyncReload(key, oldValue, executor); return newValue; } @Override public CompletableFuture<V> asyncReload(K key, V oldValue, Executor executor) {
@Override public CompletableFuture<V> asyncReload(K key, V oldValue, Executor executor) { return loader.asyncReload(key, oldValue, executor); } }
@Test public void asyncReload() throws Exception { AsyncCacheLoader<Integer, Integer> loader = (key, executor) -> CompletableFuture.completedFuture(-key); CompletableFuture<?> future = loader.asyncReload(1, 2, Runnable::run); assertThat(future.get(), is(-1)); } }
@Override public V reload(K key, V oldValue) { @SuppressWarnings("unchecked") V newValue = (V) loader.asyncReload(key, oldValue, executor); return newValue; } @Override public CompletableFuture<V> asyncReload(K key, V oldValue, Executor executor) {
@Override public CompletableFuture<V> asyncReload(K key, V oldValue, Executor executor) { return loader.asyncReload(key, oldValue, executor); } };
CompletableFuture<V> refreshFuture = (oldValue == null) ? asyncCache.loader.asyncLoad(key, asyncCache.cache().executor()) : asyncCache.loader.asyncReload(key, oldValue, asyncCache.cache().executor()); refreshFuture.whenComplete((newValue, error) -> { long loadTime = asyncCache.cache().statsTicker().read() - now;