Interface Cache<K,V>
-
public interface Cache<K,V>A cache from keys to values.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static <K,V>
Cache<K,V>bounded(int capacity)Returns new bounded cache.VcomputeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)Returns the cached value associated with the providedkey.Vget(K key)Returns the cached value associated with the providedkeyif present, ornullotherwise.voidput(K key, V value)Puts thevalueinto the cache for thekey.voidremove(K key)Removes a value forkeyif present.static <K,V>
Cache<K,V>weak()Returns new unbounded cache
-
-
-
Method Detail
-
weak
static <K,V> Cache<K,V> weak()
Returns new unbounded cacheKeys are referenced weakly and compared using identity comparison, not
Object.equals(Object).
-
bounded
static <K,V> Cache<K,V> bounded(int capacity)
Returns new bounded cache.Both keys and values are strongly referenced.
-
computeIfAbsent
V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
Returns the cached value associated with the providedkey. If no value is cached yet, computes the value usingmappingFunction, stores the result, and returns it.
-
get
@Nullable V get(K key)
Returns the cached value associated with the providedkeyif present, ornullotherwise.
-
remove
void remove(K key)
Removes a value forkeyif present.
-
-