@Nullable V getOrLoad(@Nonnull K key) throws ExecutionException { return get(key, defaultLoader); }
@Nullable @Override public V get(@Nonnull K key, @Nonnull final Callable<? extends V> valueLoader) throws ExecutionException { Preconditions.checkNotNull(valueLoader); return localCache.get(key, new CacheLoader<Object, V>() { @Override public V load(Object key) throws Exception { return valueLoader.call(); } }); }
@Nonnull Map<K, V> getAllPresent(@Nonnull Iterable<?> keys) { int hits = 0; int misses = 0; Map<K, V> result = new LinkedHashMap<>(); for (Object key : keys) { V value = get(key); if (value == null) { misses++; } else { // TODO(fry): store entry key instead of query key @SuppressWarnings("unchecked") K castKey = (K) key; result.put(castKey, value); hits++; } } return result; }