Class CaffeineVeniceStoreCache

    • 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 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 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> java.util.Map<K,​V> getAllPresent​(java.lang.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> java.util.concurrent.CompletableFuture<V> get​(K key)
        Specified by:
        get in interface VeniceStoreCache
      • 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 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> 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 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