Package play.cache

Interface AsyncCacheApi

All Known Implementing Classes:
DefaultAsyncCacheApi

public interface AsyncCacheApi
The Cache API.
  • Method Details

    • sync

      default SyncCacheApi sync()
      Returns:
      a synchronous version of this cache, which can be used to make synchronous calls.
    • get

      <T> CompletionStage<Optional<T>> get(String key)
      Retrieves an object by key.
      Type Parameters:
      T - the type of the stored object
      Parameters:
      key - the key to look up
      Returns:
      a CompletionStage containing the value wrapped in an Optional
    • getOptional

      @Deprecated default <T> CompletionStage<Optional<T>> getOptional(String key)
      Deprecated.
      Deprecated as of 2.8.0. Renamed to get(String).
      Retrieves an object by key.
      Type Parameters:
      T - the type of the stored object
      Parameters:
      key - the key to look up
      Returns:
      a CompletionStage containing the value wrapped in an Optional
    • getOrElseUpdate

      <T> CompletionStage<T> getOrElseUpdate(String key, Callable<CompletionStage<T>> block, int expiration)
      Retrieve a value from the cache, or set it from a default Callable function.
      Type Parameters:
      T - the type of the value
      Parameters:
      key - Item key.
      block - block returning value to set if key does not exist
      expiration - expiration period in seconds.
      Returns:
      a CompletionStage containing the value
    • getOrElseUpdate

      <T> CompletionStage<T> getOrElseUpdate(String key, Callable<CompletionStage<T>> block)
      Retrieve a value from the cache, or set it from a default Callable function.

      The value has no expiration.

      Type Parameters:
      T - the type of the value
      Parameters:
      key - Item key.
      block - block returning value to set if key does not exist
      Returns:
      a CompletionStage containing the value
    • set

      CompletionStage<Done> set(String key, Object value, int expiration)
      Sets a value with expiration.
      Parameters:
      key - Item key.
      value - The value to set.
      expiration - expiration in seconds
      Returns:
      a CompletionStage containing the value
    • set

      CompletionStage<Done> set(String key, Object value)
      Sets a value without expiration.
      Parameters:
      key - Item key.
      value - The value to set.
      Returns:
      a CompletionStage containing the value
    • remove

      CompletionStage<Done> remove(String key)
      Removes a value from the cache.
      Parameters:
      key - The key to remove the value for.
      Returns:
      a CompletionStage containing the value
    • removeAll

      CompletionStage<Done> removeAll()
      Removes all values from the cache. This may be useful as an admin user operation if it is supported by your cache.
      Returns:
      a CompletionStage containing either a Done when successful or an exception when unsuccessful.
      Throws:
      UnsupportedOperationException - if this cache implementation does not support removing all values.