Package play.cache
Interface SyncCacheApi
-
- All Known Implementing Classes:
DefaultSyncCacheApi
,SyncCacheApiAdapter
public interface SyncCacheApi
A synchronous API to access a Cache.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description <T> Optional<T>
get(String key)
Retrieves an object by key.default <T> Optional<T>
getOptional(String key)
Deprecated.Deprecated as of 2.8.0.<T> T
getOrElseUpdate(String key, Callable<T> block)
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
remove(String key)
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 Detail
-
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 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
<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 existexpiration
- 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.
-
-