Class CaffeineVeniceStoreCache

java.lang.Object
com.linkedin.davinci.store.cache.caffeine.CaffeineVeniceStoreCache
All Implemented Interfaces:
VeniceStoreCache

public class CaffeineVeniceStoreCache extends Object implements VeniceStoreCache
  • Constructor Summary

    Constructors
    Constructor
    Description
    CaffeineVeniceStoreCache(ObjectCacheConfig cacheConfig, com.github.benmanes.caffeine.cache.AsyncCacheLoader loadingFunction)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Discards all entries in the cache.
    void
    Performs any pending maintenance operations needed by the cache.
    get(K key)
     
    get(K key, Function<K,V> mappingFunction)
    Returns the value associated with the key in this cache, obtaining that value from the mappingFunction when a value is not already associated to the key.
    <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 the keys, creating or retrieving those values if necessary.
    <K, V> Map<K,V>
    Returns a map of the values associated with the keys in this cache.
    <K, V> V
    getIfPresent(K key)
    Returns the value associated with the key in this cache, or null if there is no cached value for the key.
    long
    Returns the approximate number of cache requests which were hits
    double
    Returns the ratio of cache requests which were hits.
    <K, V> void
    insert(K key, V value)
    Associates the value with the key in this cache.
    <K> void
    invalidate(K key)
    Discards any cached value for the key.
    long
    Returns the approximate number of cache requests which were miss
    long
    Returns the approximate number of entries in this cache.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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: VeniceStoreCache
      Returns the value associated with the key in this cache, or null if there is no cached value for the key.
      Specified by:
      getIfPresent in interface VeniceStoreCache
      Parameters:
      key - the key associated to the desired value
      Returns:
    • getAllPresent

      public <K, V> Map<K,V> getAllPresent(Iterable<K> keys)
      Description copied from interface: VeniceStoreCache
      Returns a map of the values associated with the keys 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 interface VeniceStoreCache
      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> CompletableFuture<V> get(K key)
      Specified by:
      get in interface VeniceStoreCache
    • get

      public <K, V> CompletableFuture<V> get(K key, Function<K,V> mappingFunction)
      Description copied from interface: VeniceStoreCache
      Returns the value associated with the key in this cache, obtaining that value from the mappingFunction when a value is not already associated to the key.
      Specified by:
      get in interface VeniceStoreCache
      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
    • getAll

      public <K, V> CompletableFuture<Map<K,V>> getAll(Iterable<K> keys, Function<Iterable<K>,Map<K,V>> mappingFunction)
      Description copied from interface: VeniceStoreCache
      Returns a map of the values associated with the keys, 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 interface VeniceStoreCache
      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
    • insert

      public <K, V> void insert(K key, V value)
      Description copied from interface: VeniceStoreCache
      Associates the value with the key in this cache. If the cache previously contained a value associated with the key, the old value is replaced by the new value.
      Specified by:
      insert in interface VeniceStoreCache
    • invalidate

      public <K> void invalidate(K key)
      Description copied from interface: VeniceStoreCache
      Discards any cached value for the key. 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 interface VeniceStoreCache
      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 interface VeniceStoreCache
    • 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 interface VeniceStoreCache
    • size

      public long size()
      Description copied from interface: VeniceStoreCache
      Returns the approximate number of entries in this cache.
      Specified by:
      size in interface VeniceStoreCache
    • hitRate

      public double hitRate()
      Description copied from interface: VeniceStoreCache
      Returns the ratio of cache requests which were hits. This is defined as hitCount / requestCount, or 1.0 when requestCount == 0. Note that hitRate + missRate =~ 1.0.
      Specified by:
      hitRate in interface VeniceStoreCache
      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 interface VeniceStoreCache
      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 interface VeniceStoreCache
      Returns:
      the miss count