@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 V load(K key) { @SuppressWarnings("unchecked") V newValue = (V) loader.asyncLoad(key, executor); return newValue; } @Override public V reload(K key, V oldValue) {
long now = asyncCache.cache().statsTicker().read(); 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;
@Test(expectedExceptions = UnsupportedOperationException.class) public void asyncLoadAll() throws Throwable { AsyncCacheLoader<Integer, Integer> loader = (key, executor) -> CompletableFuture.completedFuture(-key); loader.asyncLoadAll(Collections.emptyList(), Runnable::run).get(); }
loader.asyncLoadAll(proxies.keySet(), cache().executor()).whenComplete(completer); return composeResult(futures); } catch (Throwable t) {
@Override public CompletableFuture<V> asyncReload(K key, V oldValue, Executor executor) { return loader.asyncReload(key, oldValue, executor); } }
loader.asyncLoadAll(proxies.keySet(), cache.executor()).whenComplete(completer); return composeResult(futures); } catch (Throwable t) {
/** * Asynchronously computes or retrieves a replacement value corresponding to an already-cached * {@code key}. If the replacement value is not found then the mapping will be removed if * {@code null} is computed. This method is called when an existing cache entry is refreshed by * {@link Caffeine#refreshAfterWrite}, or through a call to {@link LoadingCache#refresh}. * <p> * <b>Note:</b> <i>all exceptions thrown by this method will be logged and then swallowed</i>. * * @param key the non-null key whose value should be loaded * @param oldValue the non-null old value corresponding to {@code key} * @param executor the executor with which the entry is asynchronously loaded * @return a future containing the new value associated with {@code key}, or containing * {@code null} if the mapping is to be removed */ @NonNull default CompletableFuture<V> asyncReload( @NonNull K key, @NonNull V oldValue, @NonNull Executor executor) { return asyncLoad(key, 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 load(K key) { @SuppressWarnings("unchecked") V newValue = (V) loader.asyncLoad(key, executor); return newValue; } @Override public V reload(K key, V oldValue) {
@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) {
/** * Asynchronously computes or retrieves a replacement value corresponding to an already-cached * {@code key}. If the replacement value is not found then the mapping will be removed if * {@code null} is computed. This method is called when an existing cache entry is refreshed by * {@link Caffeine#refreshAfterWrite}, or through a call to {@link LoadingCache#refresh}. * <p> * <b>Note:</b> <i>all exceptions thrown by this method will be logged and then swallowed</i>. * * @param key the non-null key whose value should be loaded * @param oldValue the non-null old value corresponding to {@code key} * @param executor the executor with which the entry is asynchronously loaded * @return a future containing the new value associated with {@code key}, or containing * {@code null} if the mapping is to be removed */ @Nonnull default CompletableFuture<V> asyncReload( @Nonnull K key, @Nonnull V oldValue, @Nonnull Executor executor) { return asyncLoad(key, executor); } }
@Override public CompletableFuture<V> asyncReload(K key, V oldValue, Executor executor) { return loader.asyncReload(key, oldValue, executor); } };