Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright (C) 2011 The Guava Authors
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
This class provides a skeletal implementation of the Cache interface to minimize the effort required to implement this interface.

To implement a cache, the programmer needs only to extend this class and provide an implementation for the LoadingCache.get(java.lang.Object) and Cache.getIfPresent(java.lang.Object) methods. getUnchecked(java.lang.Object), AbstractCache.get(java.lang.Object,java.util.concurrent.Callable), and getAll(java.lang.Iterable) are implemented in terms of get; AbstractCache.getAllPresent(java.lang.Iterable) is implemented in terms of getIfPresent; AbstractCache.putAll(java.util.Map) is implemented in terms of AbstractCache.put(java.lang.Object,java.lang.Object), AbstractCache.invalidateAll(java.lang.Iterable) is implemented in terms of AbstractCache.invalidate(java.lang.Object). The method AbstractCache.cleanUp() is a no-op. All other methods throw an java.lang.UnsupportedOperationException.

Charles Fry
public abstract class AbstractLoadingCache<K, V>
    extends AbstractCache<K, V> implements LoadingCache<K, V> {

Constructor for use by subclasses.
  protected AbstractLoadingCache() {}
  public V getUnchecked(K key) {
    try {
      return get(key);
    } catch (ExecutionException e) {
      throw new UncheckedExecutionException(e.getCause());
  public ImmutableMap<K, V> getAll(Iterable<? extends K> keysthrows ExecutionException {
    Map<K, V> result = Maps.newLinkedHashMap();
    for (K key : keys) {
      if (!result.containsKey(key)) {
    return ImmutableMap.copyOf(result);
  public final V apply(K key) {
    return getUnchecked(key);
  public void refresh(K key) {
    throw new UnsupportedOperationException();
New to GrepCode? Check out our FAQ X