Interface CaffeineCache

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      <V> CompletableFuture<V> getIfPresent​(Object key)
      Returns the future associated with key in this cache, or null if there is no cached future for key.
      Set<Object> keySet()
      Returns an unmodifiable Set view of the keys contained in this cache.
      <V> void put​(Object key, CompletableFuture<V> valueFuture)
      Associates value with key in this cache.
      void setExpireAfterAccess​(Duration duration)
      Changes the duration, initially set from the configuration, after which each entry should be automatically removed from the cache once that duration has elapsed after the entry's creation, the most recent replacement of its value, or its last read.
      void setExpireAfterWrite​(Duration duration)
      Changes the duration, initially set from the configuration, after which each entry should be automatically removed from the cache once that duration has elapsed after the entry's creation, or the most recent replacement of its value.
      void setMaximumSize​(long maximumSize)
      Changes the maximum number of entries the cache may contain.
    • Method Detail

      • keySet

        Set<Object> keySet()
        Returns an unmodifiable Set view of the keys contained in this cache. If the cache entries are modified while an iteration over the set is in progress, the set will remain unchanged.
        Returns:
        a set view of the keys contained in this cache
      • getIfPresent

        <V> CompletableFuture<V> getIfPresent​(Object key)
        Returns the future associated with key in this cache, or null if there is no cached future for key. This method is delegating to the AsyncCache.getIfPresent(Object), while recording the cache stats if they are enabled.
        Parameters:
        key - key whose associated value is to be returned
        Returns:
        the future value to which the specified key is mapped, or null if this cache does not contain a mapping for the key
        Throws:
        NullPointerException - if the specified key is null
        See Also:
        AsyncCache.getIfPresent(Object)
      • put

        <V> void put​(Object key,
                     CompletableFuture<V> valueFuture)
        Associates value with key in this cache. If the cache previously contained a value associated with key, the old value is replaced by value. If the asynchronous computation fails, the entry will be automatically removed.

        Prefer Cache.get(Object, Function) when using the conventional "if cached, return; otherwise create, cache and return" pattern.

        Parameters:
        key - key with which the specified value is to be associated
        valueFuture - value to be associated with the specified key
        Throws:
        NullPointerException - if the specified key or value is null
      • setExpireAfterWrite

        void setExpireAfterWrite​(Duration duration)
        Changes the duration, initially set from the configuration, after which each entry should be automatically removed from the cache once that duration has elapsed after the entry's creation, or the most recent replacement of its value.

        Warning: this method must not be invoked from within an atomic scope of a cache operation.

        Parameters:
        duration - the length of time after which an entry should be automatically removed
        Throws:
        IllegalStateException - if the cache was not constructed with an expire-after-write configuration value
      • setExpireAfterAccess

        void setExpireAfterAccess​(Duration duration)
        Changes the duration, initially set from the configuration, after which each entry should be automatically removed from the cache once that duration has elapsed after the entry's creation, the most recent replacement of its value, or its last read.

        Warning: this method must not be invoked from within an atomic scope of a cache operation.

        Parameters:
        duration - the length of time after which an entry should be automatically removed
        Throws:
        IllegalStateException - if the cache was not constructed with an expire-after-access configuration value
      • setMaximumSize

        void setMaximumSize​(long maximumSize)
        Changes the maximum number of entries the cache may contain.

        Warning: this method must not be invoked from within an atomic scope of a cache operation.

        Parameters:
        maximumSize - the maximum size of the cache
        Throws:
        IllegalStateException - if the cache was not constructed with a maximum-size configuration value