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 TypeMethodDescription<T> Optional<T>Retrieves an object by key.default <T> Optional<T>getOptional(String key) Deprecated.Deprecated as of 2.8.0.<T> TgetOrElseUpdate(String key, Callable<T> block) Retrieve a value from the cache, or set it from a default Callable function.<T> TgetOrElseUpdate(String key, Callable<T> block, int expiration) Retrieve a value from the cache, or set it from a default Callable function.voidRemoves a value from the cache.voidSets a value without expiration.voidSets a value with expiration.
-
Method Details
-
get
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.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:
- the object wrapped in an Optional
-
getOrElseUpdate
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:
- 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:
- the value
-
set
Sets a value with expiration.- Parameters:
key- Item key.value- The value to set.expiration- expiration in seconds
-
set
Sets a value without expiration.- Parameters:
key- Item key.value- The value to set.
-
remove
Removes a value from the cache.- Parameters:
key- The key to remove the value for.
-