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 SummaryModifier and TypeMethodDescriptionvoidclear()Discards all entries in the cache.voidclose()Performs any pending maintenance operations needed by the cache.<K,V> CompletableFuture<V> get(K key) <K,V> CompletableFuture<V> Returns the value associated with thekeyin this cache, obtaining that value from themappingFunctionwhen a value is not already associated to the key.<K,V> CompletableFuture<Map<K, V>> Returns a map of the values associated with thekeys, creating or retrieving those values if necessary.<K,V> Map<K, V> getAllPresent(Iterable<K> keys) Returns a map of the values associated with thekeysin this cache.<K,V> V getIfPresent(K key) Returns the value associated with thekeyin this cache, ornullif there is no cached value for thekey.longhitCount()Returns the approximate number of cache requests which were hitsdoublehitRate()Returns the ratio of cache requests which were hits.<K,V> void insert(K key, V value) Associates thevaluewith thekeyin this cache.<K> voidinvalidate(K key) Discards any cached value for thekey.longReturns the approximate number of cache requests which were misslongsize()Returns the approximate number of entries in this cache.
- 
Method Details- 
getIfPresent<K,V> V getIfPresent(K key) Returns the value associated with thekeyin this cache, ornullif there is no cached value for thekey.- Parameters:
- key- the key associated to the desired value
- Returns:
 
- 
getAllPresentReturns a map of the values associated with thekeysin 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:
- NullPointerException- if the specified collection is null or contains a null element
 
- 
getReturns the value associated with thekeyin this cache, obtaining that value from themappingFunctionwhen a value is not already associated to the key.- Parameters:
- key- the key with which the specified value is to be associated
- mappingFunction- 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:
- NullPointerException- if the specified key or mappingFunction is null
- IllegalStateException- if the computation is recursive (and might never finish)
- RuntimeException- if the mapping function completes exceptionally
 
- 
get
- 
getAll<K,V> CompletableFuture<Map<K,V>> getAll(Iterable<K> keys, Function<Iterable<K>, 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 returned
- mappingFunction- the function to compute the values
- Returns:
- an unmodifiable mapping of keys to values for the specified keys in this cache
- Throws:
- NullPointerException- if the specified collection is null or contains a null element, or if the map returned by the mappingFunction is null
- RuntimeException- or Error if the mappingFunction does so
 
- 
insert<K,V> void insert(K key, V value) Associates thevaluewith thekeyin 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:
- NullPointerException- if the specified key is null
 
- 
clearvoid 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.
- 
closevoid close()Performs any pending maintenance operations needed by the cache. What gets done is implementation dependant.
- 
sizelong size()Returns the approximate number of entries in this cache.
- 
hitRatedouble hitRate()Returns the ratio of cache requests which were hits. This is defined ashitCount / requestCount, or1.0whenrequestCount == 0. Note thathitRate + missRate =~ 1.0.- Returns:
- the ratio of cache requests which were hits
 
- 
hitCountlong hitCount()Returns the approximate number of cache requests which were hits- Returns:
- the hit count
 
- 
missCountlong missCount()Returns the approximate number of cache requests which were miss- Returns:
- the miss count
 
 
-