Interface CacheFunction<K,V>
-
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface CacheFunction<K,V>
Cache
's Function.Use this if your implementation throws no exception (i.e. only unchecked runtime exceptions). If your cache function throws checked exceptions, then just use a
CheckedCacheFunction
instead.- Author:
- Michael Vorburger.ch
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default CacheFunction<K,V>
from(Function<K,V> function)
Convenience mapping from java.util.function.Function.@NonNull V
get(@NonNull K key)
Calculate the value of the cache entry for the given key.default com.google.common.collect.ImmutableMap<K,V>
get(Iterable<? extends K> keys)
Implementations may wish to override this implementation if they can provide bulk implementations which avoid 1-by-1 locking overhead which single get() may incur, which is what the default implementation does.
-
-
-
Method Detail
-
get
@NonNull V get(@NonNull K key)
Calculate the value of the cache entry for the given key.- Parameters:
key
- the key for which to "calculate" (lookup, remote call, ...) a value.- Returns:
- value for the given key
-
get
default com.google.common.collect.ImmutableMap<K,V> get(Iterable<? extends K> keys)
Implementations may wish to override this implementation if they can provide bulk implementations which avoid 1-by-1 locking overhead which single get() may incur, which is what the default implementation does.- Parameters:
keys
- list of keys of cache entries- Returns:
- Map of cache keys and values (neither ever null, but may be an Optional)
-
-