@Test public void asyncLoad() throws Exception { CacheLoader<Integer, ?> loader = key -> key; CompletableFuture<?> future = loader.asyncLoad(1, Runnable::run); assertThat(future.get(), is(1)); }
@Test public void asyncLoad_exception() throws Exception { Exception e = new Exception(); CacheLoader<Integer, Integer> loader = key -> { throw e; }; try { loader.asyncLoad(1, Runnable::run).join(); } catch (CompletionException ex) { assertThat(ex.getCause(), is(sameInstance(e))); } }
V oldValue = cache().getIfPresentQuietly(key, writeTime); CompletableFuture<V> refreshFuture = (oldValue == null) ? cacheLoader().asyncLoad(key, cache().executor()) : cacheLoader().asyncReload(key, oldValue, cache().executor()); refreshFuture.whenComplete((newValue, error) -> {
V oldValue = cache().getIfPresentQuietly(key, writeTime); CompletableFuture<V> refreshFuture = (oldValue == null) ? cacheLoader().asyncLoad(key, cache().executor()) : cacheLoader().asyncReload(key, oldValue, cache().executor()); refreshFuture.whenComplete((newValue, error) -> {