@Test public void testCacheExceptionRemoval() throws Exception { final ExceptionalCacheLoader loader = new ExceptionalCacheLoader() ; loader.setGenerateLoaderErrors(true); final LocalAsyncCache<String, String> myCache = new LocalAsyncCache<String, String>(10, 10, TimeUnit.MINUTES, loader, null, "MyCache"); assertComposableFutureError(TEMPORARY_ERROR_MESSAGE,RuntimeException.class,myCache.getAsync("a")); assertComposableFutureError(TEMPORARY_ERROR_MESSAGE,RuntimeException.class,myCache.getAsync("b")); loader.setGenerateLoaderErrors(false); assertEquals(VALUE_FOR+"a", myCache.getAsync("a").get()); assertEquals(VALUE_FOR+"b", myCache.getAsync("b").get()); loader.setGenerateLoaderErrors(true); assertEquals(VALUE_FOR+"a", myCache.getAsync("a").get()); assertEquals(VALUE_FOR+"b", myCache.getAsync("b").get()); }
@Override public ComposableFuture<V> getAsync(final K key) { try { if (loadingCache != null) { final ComposableFuture<V> res = loadingCache.get(key); if (res == null) { return fromNull(); } return res.recoverWith(error -> { loadingCache.asMap().remove(key, res); return fromError(error); }); } else { final ComposableFuture<V> res = localCache.getIfPresent(key); if (res == null) { return fromNull(); } return res; } } catch (final com.google.common.util.concurrent.UncheckedExecutionException e) { return fromError(e.getCause()); } catch (final ExecutionException | UncheckedExecutionException | ExecutionError e) { return fromError(e.getCause()); } }
LocalAsyncCache implements TypedCache<K,V> { @Override public ComposableFuture<V> getAsync(final K key) { try { if (loadingCache != null) { final ComposableFuture<V> res = loadingCache.get(key); if (res == null) { return fromNull(); } return res.recoverWith(error -> { loadingCache.asMap().remove(key, res); return fromError(error); }); } else { final ComposableFuture<V> res = localCache.getIfPresent(key); if (res == null) { return fromNull(); } return res; } } catch (final com.google.common.util.concurrent.UncheckedExecutionException e) { return fromError(e.getCause()); } catch (final ExecutionException | UncheckedExecutionException | ExecutionError e) { return fromError(e.getCause()); } } }
LocalAsyncCache implements TypedCache<K,V> { @Override public ComposableFuture<V> getAsync(final K key) { try { if (loadingCache != null) { final ComposableFuture<V> res = loadingCache.get(key); if (res == null) { return fromNull(); } return res.recoverWith(error -> { loadingCache.asMap().remove(key, res); return fromError(error); }); } else { final ComposableFuture<V> res = localCache.getIfPresent(key); if (res == null) { return fromNull(); } return res; } } catch (final com.google.common.util.concurrent.UncheckedExecutionException e) { return fromError(e.getCause()); } catch (final ExecutionException | UncheckedExecutionException | ExecutionError e) { return fromError(e.getCause()); } } LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit, final CacheLoader<K, V> loader,
                         final MetricFactory metricFactory, final String cacheName);  LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit, final CacheLoader<K, V> loader,
                         final MetricFactory metricFactory, final String cacheName, final boolean failOnMissingEntries);  LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit, final CacheLoader<K, V> loader);  LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit, final MetricFactory metricFactory, final String cacheName);  LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit);  LocalAsyncCache(); }
LocalAsyncCache implements TypedCache<K,V> { @Override public ComposableFuture<V> getAsync(final K key) { try { if (loadingCache != null) { final ComposableFuture<V> res = loadingCache.get(key); if (res == null) { return fromNull(); } return res.recoverWith(error -> { loadingCache.asMap().remove(key, res); return fromError(error); }); } else { final ComposableFuture<V> res = localCache.getIfPresent(key); if (res == null) { return fromNull(); } return res; } } catch (final com.google.common.util.concurrent.UncheckedExecutionException e) { return fromError(e.getCause()); } catch (final ExecutionException | UncheckedExecutionException | ExecutionError e) { return fromError(e.getCause()); } } LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit, final CacheLoader<K, V> loader,
                         final MetricFactory metricFactory, final String cacheName);  LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit, final CacheLoader<K, V> loader,
                         final MetricFactory metricFactory, final String cacheName, final boolean failOnMissingEntries);  LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit, final CacheLoader<K, V> loader);  LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit, final MetricFactory metricFactory, final String cacheName);  LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit);  LocalAsyncCache(); @Override ComposableFuture<V> getAsync(final K key); @Override ComposableFuture<Map<K, V>> getBulkAsync(final Iterable<? extends K> keys); @Override ComposableFuture<Boolean> deleteAsync(final K key); @Override ComposableFuture<Boolean> setAsync(final K key, final V value); @Override ComposableFuture<Boolean> setIfAbsentAsync(final K key, final V value); @Override ComposableFuture<Boolean> setAsync(final K key, final EntryMapper<K, V> mapper, final int maxIterations); @Override ComposableFuture<Map<K, Boolean>> setBulkAsync(final Map<? extends K, ? extends V> entries); }
LocalAsyncCache implements TypedCache<K,V> { @Override public ComposableFuture<V> getAsync(final K key) { try { if (loadingCache != null) { final ComposableFuture<V> res = loadingCache.get(key); if (res == null) { return fromNull(); } return res.recoverWith(error -> { loadingCache.asMap().remove(key, res); return fromError(error); }); } else { final ComposableFuture<V> res = localCache.getIfPresent(key); if (res == null) { return fromNull(); } return res; } } catch (final com.google.common.util.concurrent.UncheckedExecutionException e) { return fromError(e.getCause()); } catch (final ExecutionException | UncheckedExecutionException | ExecutionError e) { return fromError(e.getCause()); } } LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit, final CacheLoader<K, V> loader,
                         final MetricFactory metricFactory, final String cacheName);  LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit, final CacheLoader<K, V> loader,
                         final MetricFactory metricFactory, final String cacheName, final boolean failOnMissingEntries);  LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit, final CacheLoader<K, V> loader);  LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit, final MetricFactory metricFactory, final String cacheName);  LocalAsyncCache(final int maximumSize, final int ttl, final TimeUnit unit);  LocalAsyncCache(); @Override ComposableFuture<V> getAsync(final K key); @Override ComposableFuture<Map<K, V>> getBulkAsync(final Iterable<? extends K> keys); @Override ComposableFuture<Boolean> deleteAsync(final K key); @Override ComposableFuture<Boolean> setAsync(final K key, final V value); @Override ComposableFuture<Boolean> setIfAbsentAsync(final K key, final V value); @Override ComposableFuture<Boolean> setAsync(final K key, final EntryMapper<K, V> mapper, final int maxIterations); @Override ComposableFuture<Map<K, Boolean>> setBulkAsync(final Map<? extends K, ? extends V> entries);  }