Package play.cache
Class DefaultSyncCacheApi
- Object
-
- play.cache.DefaultSyncCacheApi
-
- All Implemented Interfaces:
SyncCacheApi
public class DefaultSyncCacheApi extends Object implements SyncCacheApi
An implementation of SyncCacheApi that wraps AsyncCacheApiNote: 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 Summary
Fields Modifier and Type Field Description protected long
awaitTimeoutMillis
-
Constructor Summary
Constructors Constructor Description DefaultSyncCacheApi(AsyncCacheApi cacheApi)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Optional<T>
get(String key)
Retrieves an object by key.<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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface play.cache.SyncCacheApi
getOptional
-
-
-
-
Constructor Detail
-
DefaultSyncCacheApi
@Inject public DefaultSyncCacheApi(AsyncCacheApi cacheApi)
-
-
Method Detail
-
get
public <T> Optional<T> get(String key)
Description copied from interface:SyncCacheApi
Retrieves an object by key.- Specified by:
get
in interfaceSyncCacheApi
- 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 interfaceSyncCacheApi
- 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
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 interfaceSyncCacheApi
- 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 interfaceSyncCacheApi
- 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 interfaceSyncCacheApi
- 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 interfaceSyncCacheApi
- Parameters:
key
- The key to remove the value for.
-
-