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

      All Methods Instance Methods Abstract 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 the key in this cache, obtaining that value from the mappingFunction 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 the keys, 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 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 hitCount()
      Returns the approximate number of cache requests which were hits
      double hitRate()
      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 missCount()
      Returns the approximate number of cache requests which were miss
      long size()
      Returns the approximate number of entries in this cache.
    • Method Detail

      • 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> java.util.Map<K,​V> getAllPresent​(java.lang.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:
        java.lang.NullPointerException - if the specified collection is null or contains a null element
      • get

        <K,​V> java.util.concurrent.CompletableFuture<V> get​(K key,
                                                                  java.util.function.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:
        java.lang.NullPointerException - if the specified key or mappingFunction is null
        java.lang.IllegalStateException - if the computation is recursive (and might never finish)
        java.lang.RuntimeException - if the mapping function completes exceptionally
      • get

        <K,​V> java.util.concurrent.CompletableFuture<V> get​(K key)
      • getAll

        <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 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:
        java.lang.NullPointerException - if the specified collection is null or contains a null element, or if the map returned by the mappingFunction is null
        java.lang.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:
        java.lang.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