@Override public V load(K key) throws Exception { return loader.load(key); }
assertEquals(0, loadAllCount.get()); baseLoader.load(new Object()); @SuppressWarnings("unused") // go/futurereturn-lsc Future<?> possiblyIgnoredError = baseLoader.reload(new Object(), new Object()); CacheLoader<Object, Object> asyncReloader = CacheLoader.asyncReloading(baseLoader, executor); asyncReloader.load(new Object()); @SuppressWarnings("unused") // go/futurereturn-lsc Future<?> possiblyIgnoredError1 = asyncReloader.reload(new Object(), new Object());
@Override public V load(K key) throws Exception { return loader.load(key); }
@Override public V load(K key) throws Exception { return loader.load(key); }
@Override public V load(K key) throws Exception { return loader.load(key); }
/** * Computes or retrieves a replacement value corresponding to an already-cached {@code key}. This * method is called when an existing cache entry is refreshed by {@link * CacheBuilder#refreshAfterWrite}, or through a call to {@link LoadingCache#refresh}. * * <p>This implementation synchronously delegates to {@link #load}. It is recommended that it be * overridden with an asynchronous implementation when using {@link * CacheBuilder#refreshAfterWrite}. * * <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} * @return the future new value associated with {@code key}; <b>must not be null, must not return * null</b> * @throws Exception if unable to reload the result * @throws InterruptedException if this method is interrupted. {@code InterruptedException} is * treated like any other {@code Exception} in all respects except that, when it is caught, * the thread's interrupt status is set * @since 11.0 */ @GwtIncompatible // Futures public ListenableFuture<V> reload(K key, V oldValue) throws Exception { checkNotNull(key); checkNotNull(oldValue); return Futures.immediateFuture(load(key)); }
@Override public V load(K key) throws Exception { return loader.load(key); }
/** * Computes or retrieves a replacement value corresponding to an already-cached {@code key}. This * method is called when an existing cache entry is refreshed by {@link * CacheBuilder#refreshAfterWrite}, or through a call to {@link LoadingCache#refresh}. * * <p>This implementation synchronously delegates to {@link #load}. It is recommended that it be * overridden with an asynchronous implementation when using {@link * CacheBuilder#refreshAfterWrite}. * * <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} * @return the future new value associated with {@code key}; <b>must not be null, must not return * null</b> * @throws Exception if unable to reload the result * @throws InterruptedException if this method is interrupted. {@code InterruptedException} is * treated like any other {@code Exception} in all respects except that, when it is caught, * the thread's interrupt status is set * @since 11.0 */ @GwtIncompatible // Futures public ListenableFuture<V> reload(K key, V oldValue) throws Exception { checkNotNull(key); checkNotNull(oldValue); return Futures.immediateFuture(load(key)); }
V previousValue = oldValue.get(); if (previousValue == null) { V newValue = loader.load(key); return set(newValue) ? futureValue : Futures.immediateFuture(newValue);
/** * Computes or retrieves a replacement value corresponding to an already-cached {@code key}. This * method is called when an existing cache entry is refreshed by {@link * CacheBuilder#refreshAfterWrite}, or through a call to {@link LoadingCache#refresh}. * * <p>This implementation synchronously delegates to {@link #load}. It is recommended that it be * overridden with an asynchronous implementation when using {@link * CacheBuilder#refreshAfterWrite}. * * <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} * @return the future new value associated with {@code key}; <b>must not be null, must not return * null</b> * @throws Exception if unable to reload the result * @throws InterruptedException if this method is interrupted. {@code InterruptedException} is * treated like any other {@code Exception} in all respects except that, when it is caught, * the thread's interrupt status is set * @since 11.0 */ @GwtIncompatible // Futures public ListenableFuture<V> reload(K key, V oldValue) throws Exception { checkNotNull(key); checkNotNull(oldValue); return Futures.immediateFuture(load(key)); }
@Override public V load(K key) { try { V value = cacheLoader.load(key); if (value == null) { throw new InvalidCacheLoadException("null value"); } return value; } catch (RuntimeException | Error e) { throw e; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new CacheLoaderException(e); } catch (Exception e) { throw new CacheLoaderException(e); } }
V previousValue = oldValue.get(); if (previousValue == null) { V newValue = loader.load(key); return set(newValue) ? futureValue : Futures.immediateFuture(newValue);
V previousValue = oldValue.get(); if (previousValue == null) { V newValue = loader.load(key); return set(newValue) ? futureValue : Futures.immediateFuture(newValue);
@Override public Object call() throws Exception { ++numMisses; return valueLoader.load(key); } });
@Override public V call() throws Exception { return loader.load(key); } });
private static AtomicInteger getHintsInProgressFor(InetAddress destination) { try { return hintsInProgress.load(destination); } catch (Exception e) { throw new AssertionError(e); } }
@Override public V apply(K key) { try { return cacheLoader.load(key); } catch (Exception e) { throw new RuntimeException(String.format("Could not apply cache on key %s", key), e); } }
public V get(K key) throws ExecutionException { Objects.requireNonNull(key); if (config.isEnabled()) { return delegate.get(key); } try { return cacheLoader.load(key); } catch (Throwable t) { throw new RuntimeException(t); } }
@Override @SuppressFBWarnings("RV_RETURN_VALUE_IGNORED") public void refresh(final K key) { try { V val = loader.load(key); map.put(key, val); } catch (Exception ex) { throw new UncheckedExecutionException(ex); } }
@Override public void refresh(K key) { try { getUnderlyingCache().put(key, cacheLoader.load(key)); } catch (Exception e) { throw new RuntimeException(String.format("Could not refresh value for key %s", key), e); } } }