Class Cache<K,​V>

  • All Implemented Interfaces:
    Cache<K,​V>
    Direct Known Subclasses:
    LfuCache

    public abstract class Cache<K,​V>
    extends java.lang.Object
    implements Cache<K,​V>
    API MAY CHANGE

    General interface implemented by all akka-http cache implementations.

    • Constructor Summary

      Constructors 
      Constructor Description
      Cache()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract scala.concurrent.Future<V> apply​(K key, scala.Function0<scala.concurrent.Future<V>> genValue)
      Returns either the cached Future for the given key or evaluates the given value generating function producing a Future[V].
      scala.concurrent.Future<V> apply​(K key, scala.Function1<scala.concurrent.Promise<V>,​scala.runtime.BoxedUnit> f)
      Returns either the cached Future for the key or evaluates the given function which should lead to eventual completion of the promise.
      abstract void clear()
      Clears the cache by removing all entries.
      abstract scala.Option<scala.concurrent.Future<V>> get​(K key)
      Retrieves the future instance that is currently in the cache for the given key.
      scala.concurrent.Future<V> get​(K key, scala.Function0<V> block)
      Returns either the cached Future for the given key or the given value as a Future
      java.util.concurrent.CompletionStage<V> getFuture​(K key, akka.japi.Creator<java.util.concurrent.CompletionStage<V>> genValue)
      Returns either the cached CompletionStage for the given key or evaluates the given value generating function producing a `CompletionStage`.
      java.util.Set<K> getKeys()
      Returns the set of keys in the cache, in no particular order Should return in roughly constant time.
      java.util.Optional<java.util.concurrent.CompletionStage<V>> getOptional​(K key)
      Retrieves the CompletionStage instance that is currently in the cache for the given key.
      java.util.concurrent.CompletionStage<V> getOrCreateStrict​(K key, akka.japi.Creator<V> block)
      Returns either the cached CompletionStage for the given key or the given value as a CompletionStage
      java.util.concurrent.CompletionStage<V> getOrFulfil​(K key, akka.japi.Procedure<java.util.concurrent.CompletableFuture<V>> f)
      Returns either the cached CompletionStage for the key, or evaluates the given function which should lead to eventual completion of the completable future.
      abstract scala.concurrent.Future<V> getOrLoad​(K key, scala.Function1<K,​scala.concurrent.Future<V>> loadValue)
      Returns either the cached Future for the given key, or applies the given value loading function on the key, producing a Future[V].
      abstract scala.collection.immutable.Set<K> keys()
      Returns the set of keys in the cache, in no particular order Should return in roughly constant time.
      abstract scala.concurrent.Future<V> put​(K key, scala.concurrent.Future<V> mayBeValue, scala.concurrent.ExecutionContext ex)
      Cache the given future if not cached previously.
      abstract void remove​(K key)
      Removes the cache item for the given key.
      abstract int size()
      Returns the upper bound for the number of currently cached entries.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Cache

        public Cache()
    • Method Detail

      • apply

        public abstract scala.concurrent.Future<V> apply​(K key,
                                                         scala.Function0<scala.concurrent.Future<V>> genValue)
        Returns either the cached Future for the given key or evaluates the given value generating function producing a Future[V].
        Parameters:
        key - (undocumented)
        genValue - (undocumented)
        Returns:
        (undocumented)
      • apply

        public scala.concurrent.Future<V> apply​(K key,
                                                scala.Function1<scala.concurrent.Promise<V>,​scala.runtime.BoxedUnit> f)
        Returns either the cached Future for the key or evaluates the given function which should lead to eventual completion of the promise.
        Parameters:
        key - (undocumented)
        f - (undocumented)
        Returns:
        (undocumented)
      • clear

        public abstract void clear()
        Clears the cache by removing all entries.
        Specified by:
        clear in interface Cache<K,​V>
      • get

        public scala.concurrent.Future<V> get​(K key,
                                              scala.Function0<V> block)
        Returns either the cached Future for the given key or the given value as a Future
        Parameters:
        key - (undocumented)
        block - (undocumented)
        Returns:
        (undocumented)
      • get

        public abstract scala.Option<scala.concurrent.Future<V>> get​(K key)
        Retrieves the future instance that is currently in the cache for the given key. Returns None if the key has no corresponding cache entry.
        Parameters:
        key - (undocumented)
        Returns:
        (undocumented)
      • getFuture

        public final java.util.concurrent.CompletionStage<V> getFuture​(K key,
                                                                       akka.japi.Creator<java.util.concurrent.CompletionStage<V>> genValue)
        Description copied from interface: Cache
        Returns either the cached CompletionStage for the given key or evaluates the given value generating function producing a `CompletionStage`.
        Specified by:
        getFuture in interface Cache<K,​V>
      • getKeys

        public java.util.Set<K> getKeys()
        Description copied from interface: Cache
        Returns the set of keys in the cache, in no particular order Should return in roughly constant time. Note that this number might not reflect the exact keys of active, unexpired cache entries, since expired entries are only evicted upon next access (or by being thrown out by a capacity constraint).
        Specified by:
        getKeys in interface Cache<K,​V>
      • getOptional

        public java.util.Optional<java.util.concurrent.CompletionStage<V>> getOptional​(K key)
        Description copied from interface: Cache
        Retrieves the CompletionStage instance that is currently in the cache for the given key. Returns None if the key has no corresponding cache entry.
        Specified by:
        getOptional in interface Cache<K,​V>
      • getOrCreateStrict

        public java.util.concurrent.CompletionStage<V> getOrCreateStrict​(K key,
                                                                         akka.japi.Creator<V> block)
        Returns either the cached CompletionStage for the given key or the given value as a CompletionStage
        Specified by:
        getOrCreateStrict in interface Cache<K,​V>
        Parameters:
        key - (undocumented)
        block - (undocumented)
        Returns:
        (undocumented)
      • getOrFulfil

        public final java.util.concurrent.CompletionStage<V> getOrFulfil​(K key,
                                                                         akka.japi.Procedure<java.util.concurrent.CompletableFuture<V>> f)
        Description copied from interface: Cache
        Returns either the cached CompletionStage for the key, or evaluates the given function which should lead to eventual completion of the completable future.
        Specified by:
        getOrFulfil in interface Cache<K,​V>
      • getOrLoad

        public abstract scala.concurrent.Future<V> getOrLoad​(K key,
                                                             scala.Function1<K,​scala.concurrent.Future<V>> loadValue)
        Returns either the cached Future for the given key, or applies the given value loading function on the key, producing a Future[V].
        Parameters:
        key - (undocumented)
        loadValue - (undocumented)
        Returns:
        (undocumented)
      • keys

        public abstract scala.collection.immutable.Set<K> keys()
        Returns the set of keys in the cache, in no particular order Should return in roughly constant time. Note that this number might not reflect the exact keys of active, unexpired cache entries, since expired entries are only evicted upon next access (or by being thrown out by a capacity constraint).
        Returns:
        (undocumented)
      • put

        public abstract scala.concurrent.Future<V> put​(K key,
                                                       scala.concurrent.Future<V> mayBeValue,
                                                       scala.concurrent.ExecutionContext ex)
        Cache the given future if not cached previously. Or replace the old cached value on successful completion of given future. In case the given future fails, the previously cached value for that key (if any) will remain unchanged.
        Parameters:
        key - (undocumented)
        mayBeValue - (undocumented)
        ex - (undocumented)
        Returns:
        (undocumented)
      • remove

        public abstract void remove​(K key)
        Removes the cache item for the given key.
        Specified by:
        remove in interface Cache<K,​V>
        Parameters:
        key - (undocumented)
      • size

        public abstract int size()
        Returns the upper bound for the number of currently cached entries. Note that this number might not reflect the exact number of active, unexpired cache entries, since expired entries are only evicted upon next access (or by being thrown out by a capacity constraint).
        Specified by:
        size in interface Cache<K,​V>
        Returns:
        (undocumented)