public interface Cache
Modifier and Type | Method and Description |
---|---|
<T> T |
get(String key)
Fetch cached object for a given key.
|
<T> Optional<T> |
getOptional(String key)
Optionaly fetch cached object for a given key.
|
<T> T |
getOrSetDefault(String key, int ttlSeconds, Supplier<T> defaultValueSupplier)
Fetch cached object for a given key or set an expiring default value.
|
<T> T |
getOrSetDefault(String key, int ttlSeconds, T defaultValue)
Fetch cached object for a given key or set an expiring default value.
|
<T> T |
getOrSetDefault(String key, Supplier<T> defaultValueSupplier)
Fetch cached object for a given key or set a non-expiring default value.
|
<T> T |
getOrSetDefault(String key, T defaultValue)
Fetch cached object for a given key or set a non-expiring default value.
|
boolean |
has(String key)
Check if the Cache has an object for a given key.
|
void |
remove(String key)
Remove a Cache entry.
|
<T> void |
set(int ttlSeconds, String key, T value)
Set an expiring object for a given key in the Cache.
|
<T> void |
set(String key, T value)
Set a non-expiring object for a given key in the Cache.
|
boolean has(String key)
key
- Cache Key
<T> T get(String key)
T
- Object Type
key
- Cache Key
<T> Optional<T> getOptional(String key)
T
- Object Type
key
- Cache Key
<T> T getOrSetDefault(String key, T defaultValue)
If the cache has a non-expired object for the given key, it is returned.
Otherwise, the given default value is set in the cache and returned.
T
- Object Type
key
- Cache Key
defaultValue
- Default Value
<T> T getOrSetDefault(String key, Supplier<T> defaultValueSupplier)
If the cache has a non-expired object for the given key, it is returned.
Otherwise, the given default value is set in the cache and returned.
T
- Object Type
key
- Cache Key
defaultValueSupplier
- Default Value Supplier
<T> T getOrSetDefault(String key, int ttlSeconds, T defaultValue)
If the cache has a non-expired object for the given key, it is returned.
Otherwise, the given default value is set in the cache and returned.
T
- Object Type
key
- Cache Key
ttlSeconds
- Default Value Time To Live in seconds. If 0 (ZERO), then the entry will never expire
defaultValue
- Default Value
<T> T getOrSetDefault(String key, int ttlSeconds, Supplier<T> defaultValueSupplier)
If the cache has a non-expired object for the given key, it is returned.
Otherwise, the given default value is set in the cache and returned.
T
- Object Type
key
- Cache Key
ttlSeconds
- Default Value Time To Live in seconds. If 0 (ZERO), then the entry will never expire
defaultValueSupplier
- Default Value Supplier
<T> void set(String key, T value)
T
- Object Type
key
- Cache Key
value
- Value Object
<T> void set(int ttlSeconds, String key, T value)
T
- Object Type
ttlSeconds
- Time To Live in seconds. If 0 (ZERO), then the entry will not expire
key
- Cache Key
value
- Value Object
void remove(String key)
key
- Key of the entry to remove