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

    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.
  • Method Details

    • getIfPresent

      <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.
      Parameters:
      key - the key associated to the desired value
      Returns:
    • getAllPresent

      <K, V> Map<K,V> getAllPresent(Iterable<K> keys)
      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)

      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
    • get

      <K, V> CompletableFuture<V> 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.
      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

      <K, V> CompletableFuture<V> get(K key)
    • 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 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.
      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 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.
      Parameters:
      key -
      value -
    • invalidate

      <K> void invalidate(K key)
      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.
      Parameters:
      key - the key whose mapping is to be removed from the cache
      Throws:
      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 as hitCount / requestCount, or 1.0 when requestCount == 0. Note that hitRate + 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