Package play.cache

Class DefaultAsyncCacheApi

java.lang.Object
play.cache.DefaultAsyncCacheApi
All Implemented Interfaces:
AsyncCacheApi

@Singleton public class DefaultAsyncCacheApi extends Object implements AsyncCacheApi
Adapts a Scala AsyncCacheApi to a Java AsyncCacheApi. This is Play's default Java AsyncCacheApi implementation.
  • Constructor Details

    • DefaultAsyncCacheApi

      @Inject public DefaultAsyncCacheApi(play.api.cache.AsyncCacheApi cacheApi)
  • Method Details

    • sync

      public SyncCacheApi sync()
      Specified by:
      sync in interface AsyncCacheApi
      Returns:
      a synchronous version of this cache, which can be used to make synchronous calls.
    • get

      public <T> CompletionStage<Optional<T>> get(String key)
      Description copied from interface: AsyncCacheApi
      Retrieves an object by key.
      Specified by:
      get in interface AsyncCacheApi
      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

      public <T> CompletionStage<T> getOrElseUpdate(String key, Callable<CompletionStage<T>> block, int expiration)
      Description copied from interface: AsyncCacheApi
      Retrieve a value from the cache, or set it from a default Callable function.
      Specified by:
      getOrElseUpdate in interface AsyncCacheApi
      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

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

      The value has no expiration.

      Specified by:
      getOrElseUpdate in interface AsyncCacheApi
      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

      public CompletionStage<Done> set(String key, Object value, int expiration)
      Description copied from interface: AsyncCacheApi
      Sets a value with expiration.
      Specified by:
      set in interface AsyncCacheApi
      Parameters:
      key - Item key.
      value - The value to set.
      expiration - expiration in seconds
      Returns:
      a CompletionStage containing the value
    • set

      public CompletionStage<Done> set(String key, Object value)
      Description copied from interface: AsyncCacheApi
      Sets a value without expiration.
      Specified by:
      set in interface AsyncCacheApi
      Parameters:
      key - Item key.
      value - The value to set.
      Returns:
      a CompletionStage containing the value
    • remove

      public CompletionStage<Done> remove(String key)
      Description copied from interface: AsyncCacheApi
      Removes a value from the cache.
      Specified by:
      remove in interface AsyncCacheApi
      Parameters:
      key - The key to remove the value for.
      Returns:
      a CompletionStage containing the value
    • removeAll

      public CompletionStage<Done> removeAll()
      Description copied from interface: AsyncCacheApi
      Removes all values from the cache. This may be useful as an admin user operation if it is supported by your cache.
      Specified by:
      removeAll in interface AsyncCacheApi
      Returns:
      a CompletionStage containing either a Done when successful or an exception when unsuccessful.