Package play.cache

Class DefaultSyncCacheApi

java.lang.Object
play.cache.DefaultSyncCacheApi
All Implemented Interfaces:
SyncCacheApi

public class DefaultSyncCacheApi extends Object implements SyncCacheApi
An implementation of SyncCacheApi that wraps AsyncCacheApi

Note: this class is really not the "default" implementation of the CacheApi in Play. SyncCacheApiAdapter is actually used in the default Ehcache implementation. A better name for this class might be "BlockingSyncCacheApi" since it blocks on the futures from the async implementation.

  • Field Details

    • awaitTimeoutMillis

      protected long awaitTimeoutMillis
  • Constructor Details

    • DefaultSyncCacheApi

      @Inject public DefaultSyncCacheApi(AsyncCacheApi cacheApi)
  • Method Details

    • get

      public <T> Optional<T> get(String key)
      Description copied from interface: SyncCacheApi
      Retrieves an object by key.
      Specified by:
      get in interface SyncCacheApi
      Type Parameters:
      T - the type of the stored object
      Parameters:
      key - the key to look up
      Returns:
      the object wrapped in an Optional
    • getOrElseUpdate

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

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

      The value has no expiration.

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

      public void set(String key, Object value, int expiration)
      Description copied from interface: SyncCacheApi
      Sets a value with expiration.
      Specified by:
      set in interface SyncCacheApi
      Parameters:
      key - Item key.
      value - The value to set.
      expiration - expiration in seconds
    • set

      public void set(String key, Object value)
      Description copied from interface: SyncCacheApi
      Sets a value without expiration.
      Specified by:
      set in interface SyncCacheApi
      Parameters:
      key - Item key.
      value - The value to set.
    • remove

      public void remove(String key)
      Description copied from interface: SyncCacheApi
      Removes a value from the cache.
      Specified by:
      remove in interface SyncCacheApi
      Parameters:
      key - The key to remove the value for.