Package play.cache
Interface AsyncCacheApi
- All Known Implementing Classes:
DefaultAsyncCacheApi
public interface AsyncCacheApi
The Cache API.
-
Method Summary
Modifier and TypeMethodDescription<T> CompletionStage<Optional<T>>Retrieves an object by key.default <T> CompletionStage<Optional<T>>getOptional(String key) Deprecated.Deprecated as of 2.8.0.<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.Removes a value from the cache.Removes all values from the cache.Sets a value without expiration.Sets a value with expiration.default SyncCacheApisync()
-
Method Details
-
sync
- Returns:
- a synchronous version of this cache, which can be used to make synchronous calls.
-
get
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.Deprecated as of 2.8.0. Renamed toget(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 existexpiration- expiration period in seconds.- Returns:
- a CompletionStage containing the value
-
getOrElseUpdate
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
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
Sets a value without expiration.- Parameters:
key- Item key.value- The value to set.- Returns:
- a CompletionStage containing the value
-
remove
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.
-