Class CaffeineVeniceStoreCache
- java.lang.Object
-
- com.linkedin.davinci.store.cache.caffeine.CaffeineVeniceStoreCache
-
- All Implemented Interfaces:
VeniceStoreCache
public class CaffeineVeniceStoreCache extends java.lang.Object implements VeniceStoreCache
-
-
Constructor Summary
Constructors Constructor Description CaffeineVeniceStoreCache(ObjectCacheConfig cacheConfig, com.github.benmanes.caffeine.cache.AsyncCacheLoader loadingFunction)
-
Method Summary
All Methods Instance Methods Concrete 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.
-
-
-
Constructor Detail
-
CaffeineVeniceStoreCache
public CaffeineVeniceStoreCache(ObjectCacheConfig cacheConfig, com.github.benmanes.caffeine.cache.AsyncCacheLoader loadingFunction)
-
-
Method Detail
-
getIfPresent
public <K,V> V getIfPresent(K key)
Description copied from interface:VeniceStoreCache
Returns the value associated with thekey
in this cache, ornull
if there is no cached value for thekey
.- Specified by:
getIfPresent
in interfaceVeniceStoreCache
- Parameters:
key
- the key associated to the desired value- Returns:
-
getAllPresent
public <K,V> java.util.Map<K,V> getAllPresent(java.lang.Iterable<K> keys)
Description copied from interface:VeniceStoreCache
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)- Specified by:
getAllPresent
in 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
public <K,V> java.util.concurrent.CompletableFuture<V> get(K key)
- Specified by:
get
in interfaceVeniceStoreCache
-
get
public <K,V> java.util.concurrent.CompletableFuture<V> get(K key, java.util.function.Function<K,V> mappingFunction)
Description copied from interface:VeniceStoreCache
Returns the value associated with thekey
in this cache, obtaining that value from themappingFunction
when a value is not already associated to the key.- Specified by:
get
in 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> 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)
Description copied from interface:VeniceStoreCache
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.- Specified by:
getAll
in 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:VeniceStoreCache
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
.- Specified by:
insert
in interfaceVeniceStoreCache
-
invalidate
public <K> void invalidate(K key)
Description copied from interface:VeniceStoreCache
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.- Specified by:
invalidate
in interfaceVeniceStoreCache
- Parameters:
key
- the key whose mapping is to be removed from the cache
-
clear
public void clear()
Description copied from interface:VeniceStoreCache
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.- Specified by:
clear
in interfaceVeniceStoreCache
-
close
public void close()
Description copied from interface:VeniceStoreCache
Performs any pending maintenance operations needed by the cache. What gets done is implementation dependant.- Specified by:
close
in interfaceVeniceStoreCache
-
size
public long size()
Description copied from interface:VeniceStoreCache
Returns the approximate number of entries in this cache.- Specified by:
size
in interfaceVeniceStoreCache
-
hitRate
public double hitRate()
Description copied from interface:VeniceStoreCache
Returns the ratio of cache requests which were hits. This is defined ashitCount / requestCount
, or1.0
whenrequestCount == 0
. Note thathitRate + missRate =~ 1.0
.- Specified by:
hitRate
in interfaceVeniceStoreCache
- Returns:
- the ratio of cache requests which were hits
-
hitCount
public long hitCount()
Description copied from interface:VeniceStoreCache
Returns the approximate number of cache requests which were hits- Specified by:
hitCount
in interfaceVeniceStoreCache
- Returns:
- the hit count
-
missCount
public long missCount()
Description copied from interface:VeniceStoreCache
Returns the approximate number of cache requests which were miss- Specified by:
missCount
in interfaceVeniceStoreCache
- Returns:
- the miss count
-
-