Package com.linkedin.davinci.store.cache
Interface VeniceStoreCache
-
- Type Parameters:
K
- The key type that should be returned from the cache. Should match the type that is preferred to be read.V
-
- All Known Implementing Classes:
CaffeineVeniceStoreCache
public interface VeniceStoreCache
Interface for a cache on a venice store. This interface is meant to decouple venice code from different cache implementations (for which, there are many).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clear()
Discards all entries in the cache.void
close()
Performs any pending maintenance operations needed by the cache.<K,V>
java.util.concurrent.CompletableFuture<V>get(K key)
<K,V>
java.util.concurrent.CompletableFuture<V>get(K key, java.util.function.Function<K,V> mappingFunction)
Returns the value associated with thekey
in this cache, obtaining that value from themappingFunction
when a value is not already associated to the key.<K,V>
java.util.concurrent.CompletableFuture<java.util.Map<K,V>>getAll(java.lang.Iterable<K> keys, java.util.function.Function<java.lang.Iterable<K>,java.util.Map<K,V>> mappingFunction)
Returns a map of the values associated with thekeys
, creating or retrieving those values if necessary.<K,V>
java.util.Map<K,V>getAllPresent(java.lang.Iterable<K> keys)
Returns a map of the values associated with thekeys
in this cache.<K,V>
VgetIfPresent(K key)
Returns the value associated with thekey
in this cache, ornull
if there is no cached value for thekey
.long
hitCount()
Returns the approximate number of cache requests which were hitsdouble
hitRate()
Returns the ratio of cache requests which were hits.<K,V>
voidinsert(K key, V value)
Associates thevalue
with thekey
in this cache.<K> void
invalidate(K key)
Discards any cached value for thekey
.long
missCount()
Returns the approximate number of cache requests which were misslong
size()
Returns the approximate number of entries in this cache.
-
-
-
Method Detail
-
getIfPresent
<K,V> V getIfPresent(K key)
Returns the value associated with thekey
in this cache, ornull
if there is no cached value for thekey
.- Parameters:
key
- the key associated to the desired value- Returns:
-
getAllPresent
<K,V> java.util.Map<K,V> getAllPresent(java.lang.Iterable<K> keys)
Returns a map of the values associated with thekeys
in this cache. The returned map will only contain entries which are already present in the cache. Duplicate keys may be ignored (depends on the implementation)- Parameters:
keys
- the keys whose associated values are to be returned- Returns:
- the unmodifiable mapping of keys to values for the specified keys found in this cache
- Throws:
java.lang.NullPointerException
- if the specified collection is null or contains a null element
-
get
<K,V> java.util.concurrent.CompletableFuture<V> get(K key, java.util.function.Function<K,V> mappingFunction)
Returns the value associated with thekey
in this cache, obtaining that value from themappingFunction
when a value is not already associated to the key.- Parameters:
key
- the key with which the specified value is to be associatedmappingFunction
- the function to compute a value- Returns:
- the current (existing or computed) value associated with the specified key, or null if the computed value is null
- Throws:
java.lang.NullPointerException
- if the specified key or mappingFunction is nulljava.lang.IllegalStateException
- if the computation is recursive (and might never finish)java.lang.RuntimeException
- if the mapping function completes exceptionally
-
get
<K,V> java.util.concurrent.CompletableFuture<V> get(K key)
-
getAll
<K,V> java.util.concurrent.CompletableFuture<java.util.Map<K,V>> getAll(java.lang.Iterable<K> keys, java.util.function.Function<java.lang.Iterable<K>,java.util.Map<K,V>> mappingFunction)
Returns a map of the values associated with thekeys
, creating or retrieving those values if necessary. The returned map contains entries that were already cached, combined with the newly loaded entries; it will never contain null keys or values.- Parameters:
keys
- the keys whose associated values are to be returnedmappingFunction
- the function to compute the values- Returns:
- an unmodifiable mapping of keys to values for the specified keys in this cache
- Throws:
java.lang.NullPointerException
- if the specified collection is null or contains a null element, or if the map returned by the mappingFunction is nulljava.lang.RuntimeException
- or Error if the mappingFunction does so
-
insert
<K,V> void insert(K key, V value)
Associates thevalue
with thekey
in this cache. If the cache previously contained a value associated with thekey
, the old value is replaced by the newvalue
.- Parameters:
key
-value
-
-
invalidate
<K> void invalidate(K key)
Discards any cached value for thekey
. The behavior of this operation is undefined for an entry that is being loaded (or reloaded) and is otherwise not present.- Parameters:
key
- the key whose mapping is to be removed from the cache- Throws:
java.lang.NullPointerException
- if the specified key is null
-
clear
void clear()
Discards all entries in the cache. The behavior of this operation is undefined for an entry that is being loaded (or reloaded) and is otherwise not present.
-
close
void close()
Performs any pending maintenance operations needed by the cache. What gets done is implementation dependant.
-
size
long size()
Returns the approximate number of entries in this cache.
-
hitRate
double hitRate()
Returns the ratio of cache requests which were hits. This is defined ashitCount / requestCount
, or1.0
whenrequestCount == 0
. Note thathitRate + missRate =~ 1.0
.- Returns:
- the ratio of cache requests which were hits
-
hitCount
long hitCount()
Returns the approximate number of cache requests which were hits- Returns:
- the hit count
-
missCount
long missCount()
Returns the approximate number of cache requests which were miss- Returns:
- the miss count
-
-