Class CaffeineVeniceStoreCache
java.lang.Object
com.linkedin.davinci.store.cache.caffeine.CaffeineVeniceStoreCache
- All Implemented Interfaces:
VeniceStoreCache
-
Constructor Summary
ConstructorsConstructorDescriptionCaffeineVeniceStoreCache(ObjectCacheConfig cacheConfig, com.github.benmanes.caffeine.cache.AsyncCacheLoader loadingFunction) -
Method Summary
Modifier 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.
-
Constructor Details
-
CaffeineVeniceStoreCache
public CaffeineVeniceStoreCache(ObjectCacheConfig cacheConfig, com.github.benmanes.caffeine.cache.AsyncCacheLoader loadingFunction)
-
-
Method Details
-
getIfPresent
public <K,V> V getIfPresent(K key) Description copied from interface:VeniceStoreCacheReturns the value associated with thekeyin this cache, ornullif there is no cached value for thekey.- Specified by:
getIfPresentin interfaceVeniceStoreCache- Parameters:
key- the key associated to the desired value- Returns:
-
getAllPresent
Description copied from interface:VeniceStoreCacheReturns 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)- Specified by:
getAllPresentin interfaceVeniceStoreCache- 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
-
get
- Specified by:
getin interfaceVeniceStoreCache
-
get
Description copied from interface:VeniceStoreCacheReturns the value associated with thekeyin this cache, obtaining that value from themappingFunctionwhen a value is not already associated to the key.- Specified by:
getin interfaceVeniceStoreCache- 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
-
getAll
public <K,V> CompletableFuture<Map<K,V>> getAll(Iterable<K> keys, Function<Iterable<K>, Map<K, V>> mappingFunction) Description copied from interface:VeniceStoreCacheReturns 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.- Specified by:
getAllin interfaceVeniceStoreCache- 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
-
insert
public <K,V> void insert(K key, V value) Description copied from interface:VeniceStoreCacheAssociates thevaluewith thekeyin this cache. If the cache previously contained a value associated with thekey, the old value is replaced by the newvalue.- Specified by:
insertin interfaceVeniceStoreCache
-
invalidate
public <K> void invalidate(K key) Description copied from interface:VeniceStoreCacheDiscards 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.- Specified by:
invalidatein interfaceVeniceStoreCache- Parameters:
key- the key whose mapping is to be removed from the cache
-
clear
public void clear()Description copied from interface:VeniceStoreCacheDiscards 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.- Specified by:
clearin interfaceVeniceStoreCache
-
close
public void close()Description copied from interface:VeniceStoreCachePerforms any pending maintenance operations needed by the cache. What gets done is implementation dependant.- Specified by:
closein interfaceVeniceStoreCache
-
size
public long size()Description copied from interface:VeniceStoreCacheReturns the approximate number of entries in this cache.- Specified by:
sizein interfaceVeniceStoreCache
-
hitRate
public double hitRate()Description copied from interface:VeniceStoreCacheReturns the ratio of cache requests which were hits. This is defined ashitCount / requestCount, or1.0whenrequestCount == 0. Note thathitRate + missRate =~ 1.0.- Specified by:
hitRatein interfaceVeniceStoreCache- Returns:
- the ratio of cache requests which were hits
-
hitCount
public long hitCount()Description copied from interface:VeniceStoreCacheReturns the approximate number of cache requests which were hits- Specified by:
hitCountin interfaceVeniceStoreCache- Returns:
- the hit count
-
missCount
public long missCount()Description copied from interface:VeniceStoreCacheReturns the approximate number of cache requests which were miss- Specified by:
missCountin interfaceVeniceStoreCache- Returns:
- the miss count
-