Modifier and Type | Class and Description |
---|---|
static class |
CacheAdapter.CacheEvent
Cache Event.
|
Modifier | Constructor and Description |
---|---|
protected |
CacheAdapter()
Create a Cache without metrics handling.
|
protected |
CacheAdapter(Function<CacheAdapter.CacheEvent,CacheAdapter.CacheEvent.Closeable> handler)
Create a Cache with metrics handling.
|
Modifier and Type | Method and Description |
---|---|
protected abstract <T> T |
doGet(String key)
Concrete GET.
|
protected abstract void |
doRemove(String key)
Concrete REMOVE.
|
protected abstract <T> void |
doSet(int ttlSeconds, String key, T value)
Concrete SET.
|
<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.
|
protected CacheAdapter()
protected CacheAdapter(Function<CacheAdapter.CacheEvent,CacheAdapter.CacheEvent.Closeable> handler)
handler
- Metrics handler
public final boolean has(String key)
Cache
public final <T> T get(String key)
Cache
public final <T> Optional<T> getOptional(String key)
Cache
getOptional
in interface
Cache
T
- Object Type
key
- Cache Key
public final <T> T getOrSetDefault(String key, T defaultValue)
Cache
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.
getOrSetDefault
in interface
Cache
T
- Object Type
key
- Cache Key
defaultValue
- Default Value
public final <T> T getOrSetDefault(String key, Supplier<T> defaultValueSupplier)
Cache
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.
getOrSetDefault
in interface
Cache
T
- Object Type
key
- Cache Key
defaultValueSupplier
- Default Value Supplier
public final <T> T getOrSetDefault(String key, int ttlSeconds, T defaultValue)
Cache
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.
getOrSetDefault
in interface
Cache
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
public final <T> T getOrSetDefault(String key, int ttlSeconds, Supplier<T> defaultValueSupplier)
Cache
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.
getOrSetDefault
in interface
Cache
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
public final <T> void set(String key, T value)
Cache
public final <T> void set(int ttlSeconds, String key, T value)
Cache
public final void remove(String key)
Cache
protected abstract <T> T doGet(String key)
T
- Parameterized type of value
key
- Cache Key
protected abstract <T> void doSet(int ttlSeconds, String key, T value)
T
- Parameterized type of value
ttlSeconds
- TTL in seconds
key
- Cache Key
value
- Value
protected abstract void doRemove(String key)
key
- Cache Key