Class Cache<K,V>

java.lang.Object
org.apache.pekko.http.caching.scaladsl.Cache<K,V>
All Implemented Interfaces:
Cache<K,V>
Direct Known Subclasses:
LfuCache

public abstract class Cache<K,V> extends Object implements Cache<K,V>
API MAY CHANGE

General interface implemented by all cache implementations.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    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
    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
    getFuture(K key, org.apache.pekko.japi.function.Creator<CompletionStage<V>> genValue)
    Returns either the cached CompletionStage for the given key or evaluates the given value generating function producing a `CompletionStage`.
    Returns the set of keys in the cache, in no particular order Should return in roughly constant time.
    Retrieves the CompletionStage instance that is currently in the cache for the given key.
    getOrCreateStrict(K key, org.apache.pekko.japi.function.Creator<V> block)
    Returns either the cached CompletionStage for the given key or the given value as a CompletionStage
    getOrFulfil(K key, org.apache.pekko.japi.function.Procedure<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>
    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
    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 Details

    • Cache

      public Cache()
  • Method Details

    • 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 CompletionStage<V> getFuture(K key, org.apache.pekko.japi.function.Creator<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 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 Optional<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 CompletionStage<V> getOrCreateStrict(K key, org.apache.pekko.japi.function.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 CompletionStage<V> getOrFulfil(K key, org.apache.pekko.japi.function.Procedure<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)