Interface Cache<K,​V>

  • Type Parameters:
    K - the type of keys maintained by this cache
    V - the type of mapped values
    All Known Implementing Classes:
    DefaultCache

    public interface Cache<K,​V>
    A thread-safe cache that provides a unified API for both Kotlin and Java applications.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void clear()
      Removes all mappings from this cache.
      CompletableFuture<Void> clearAsync()
      Asynchronously removes all mappings from this cache.
      CacheConfig<K,​V> config()
      Returns the cache configuration.
      boolean containsKey​(K key)
      Returns true if this cache contains a mapping for the specified key.
      Set<Map.Entry<K,​V>> entries()
      Returns a view of all the key-value pairs in this cache.
      V get​(K key)
      Returns the value associated with the key in this cache, or null if there is no cached value for the key.
      CompletableFuture<V> getAsync​(K key)
      Asynchronously returns the value associated with the key in this cache.
      Set<K> keys()
      Returns a view of all the keys in this cache.
      void put​(K key, V value)
      Associates the specified value with the specified key in this cache.
      CompletableFuture<Void> putAsync​(K key, V value)
      Asynchronously associates the specified value with the specified key in this cache.
      V remove​(K key)
      Removes the mapping for a key from this cache if it is present.
      CompletableFuture<V> removeAsync​(K key)
      Asynchronously removes the mapping for a key from this cache if it is present.
      long size()
      Returns the approximate number of entries in this cache.
      CacheStats stats()
      Returns the cache statistics.
      Collection<V> values()
      Returns a view of all the values in this cache.
    • Method Detail

      • get

        V get​(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 whose associated value is to be returned
        Returns:
        the value to which the specified key is mapped, or null if this cache contains no mapping for the key
      • put

        void put​(K key,
                 V value)
        Associates the specified value with the specified key in this cache.
        Parameters:
        key - key with which the specified value is to be associated
        value - value to be associated with the specified key
      • remove

        V remove​(K key)
        Removes the mapping for a key from this cache if it is present.
        Parameters:
        key - key whose mapping is to be removed from the cache
        Returns:
        the previous value associated with key, or null if there was no mapping for key
      • clear

        void clear()
        Removes all mappings from this cache.
      • size

        long size()
        Returns the approximate number of entries in this cache.
        Returns:
        the number of entries in this cache
      • containsKey

        boolean containsKey​(K key)
        Returns true if this cache contains a mapping for the specified key.
        Parameters:
        key - key whose presence in this cache is to be tested
        Returns:
        true if this cache contains a mapping for the specified key
      • keys

        Set<K> keys()
        Returns a view of all the keys in this cache.
        Returns:
        a set view of the keys contained in this cache
      • values

        Collection<V> values()
        Returns a view of all the values in this cache.
        Returns:
        a collection view of the values contained in this cache
      • entries

        Set<Map.Entry<K,​V>> entries()
        Returns a view of all the key-value pairs in this cache.
        Returns:
        a set view of the mappings contained in this cache
      • stats

        CacheStats stats()
        Returns the cache statistics.
        Returns:
        the cache statistics
      • getAsync

        CompletableFuture<V> getAsync​(K key)
        Asynchronously returns the value associated with the key in this cache.
        Parameters:
        key - the key whose associated value is to be returned
        Returns:
        a CompletableFuture that will be completed with the value to which the specified key is mapped, or null if this cache contains no mapping for the key
      • putAsync

        CompletableFuture<Void> putAsync​(K key,
                                         V value)
        Asynchronously associates the specified value with the specified key in this cache.
        Parameters:
        key - key with which the specified value is to be associated
        value - value to be associated with the specified key
        Returns:
        a CompletableFuture that will be completed when the operation is done
      • removeAsync

        CompletableFuture<V> removeAsync​(K key)
        Asynchronously removes the mapping for a key from this cache if it is present.
        Parameters:
        key - key whose mapping is to be removed from the cache
        Returns:
        a CompletableFuture that will be completed with the previous value associated with key, or null if there was no mapping for key
      • clearAsync

        CompletableFuture<Void> clearAsync()
        Asynchronously removes all mappings from this cache.
        Returns:
        a CompletableFuture that will be completed when the operation is done
      • config

        CacheConfig<K,​V> config()
        Returns the cache configuration.
        Returns:
        the cache configuration