Package play.cache
Class DefaultAsyncCacheApi
- 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 Summary
Constructors Constructor Description DefaultAsyncCacheApi(play.api.cache.AsyncCacheApi cacheApi)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> CompletionStage<Optional<T>>get(String key)Retrieves an object by key.<T> CompletionStage<T>getOrElseUpdate(String key, Callable<CompletionStage<T>> block)Retrieve a value from the cache, or set it from a default Callable function.<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.CompletionStage<Done>remove(String key)Removes a value from the cache.CompletionStage<Done>removeAll()Removes all values from the cache.CompletionStage<Done>set(String key, Object value)Sets a value without expiration.CompletionStage<Done>set(String key, Object value, int expiration)Sets a value with expiration.SyncCacheApisync()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface play.cache.AsyncCacheApi
getOptional
-
-
-
-
Method Detail
-
sync
public SyncCacheApi sync()
- Specified by:
syncin interfaceAsyncCacheApi- 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:AsyncCacheApiRetrieves an object by key.- Specified by:
getin interfaceAsyncCacheApi- 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:AsyncCacheApiRetrieve a value from the cache, or set it from a default Callable function.- Specified by:
getOrElseUpdatein interfaceAsyncCacheApi- Type Parameters:
T- the type of the value- Parameters:
key- Item key.block- block returning value to set if key does not existexpiration- 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:AsyncCacheApiRetrieve a value from the cache, or set it from a default Callable function.The value has no expiration.
- Specified by:
getOrElseUpdatein interfaceAsyncCacheApi- 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:AsyncCacheApiSets a value with expiration.- Specified by:
setin interfaceAsyncCacheApi- 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:AsyncCacheApiSets a value without expiration.- Specified by:
setin interfaceAsyncCacheApi- 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:AsyncCacheApiRemoves a value from the cache.- Specified by:
removein interfaceAsyncCacheApi- Parameters:
key- The key to remove the value for.- Returns:
- a CompletionStage containing the value
-
removeAll
public CompletionStage<Done> removeAll()
Description copied from interface:AsyncCacheApiRemoves all values from the cache. This may be useful as an admin user operation if it is supported by your cache.- Specified by:
removeAllin interfaceAsyncCacheApi- Returns:
- a CompletionStage containing either a Done when successful or an exception when unsuccessful.
-
-