Package play.cache

Interface SyncCacheApi

All Known Implementing Classes:
DefaultSyncCacheApi, SyncCacheApiAdapter

public interface SyncCacheApi
A synchronous API to access a Cache.
  • Method Summary

    Modifier and Type
    Method
    Description
    <T> Optional<T>
    get(String key)
    Retrieves an object by key.
    default <T> Optional<T>
    Deprecated.
    Deprecated as of 2.8.0.
    <T> T
    Retrieve a value from the cache, or set it from a default Callable function.
    <T> T
    getOrElseUpdate(String key, Callable<T> block, int expiration)
    Retrieve a value from the cache, or set it from a default Callable function.
    void
    Removes a value from the cache.
    void
    set(String key, Object value)
    Sets a value without expiration.
    void
    set(String key, Object value, int expiration)
    Sets a value with expiration.
  • Method Details

    • get

      <T> 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:
      the object wrapped in an Optional
    • getOptional

      @Deprecated default <T> 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:
      the object wrapped in an Optional
    • getOrElseUpdate

      <T> T getOrElseUpdate(String key, Callable<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:
      the value
    • getOrElseUpdate

      <T> T getOrElseUpdate(String key, Callable<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:
      the value
    • set

      void 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
    • set

      void set(String key, Object value)
      Sets a value without expiration.
      Parameters:
      key - Item key.
      value - The value to set.
    • remove

      void remove(String key)
      Removes a value from the cache.
      Parameters:
      key - The key to remove the value for.