K - Type of the key that is used to store and lookup entries. Keys should be kept simple
as they might be stored in memory. A Key relies on correct implementations of HashCode
and Equals.V - Type of entries that can be stored and retrieved from the cache.public interface Cache<K,V>
| Modifier and Type | Field and Description |
|---|---|
static long |
UNLIMITED_IDLE_TIME |
| Modifier and Type | Method and Description |
|---|---|
void |
cleanUp()
Cleanup the cache.
|
void |
delete(K key)
Manually remove an entry from the cache.
|
<T extends V> |
get(K key)
Retrieve an entry from the cache if it is available.
|
long |
getDefaultMaxIdleTime()
Get the default max idle time for cache entries.
|
long |
getDefaultTtl()
Retrieve the default time to live for cache entries.
|
MetaData |
getMetaData(K key)
Retrieve the
MetaData of a cached entry if it is available. |
String |
getName()
Get the name of this cache.
|
CacheStatistics |
getStatistics()
Get statistics of the cache like hitrate, or size.
|
<T extends V> |
getWithErrors(K key)
Retrieve an entry from the cache if it is available.
|
<T extends V> |
put(K key,
T data)
Store an entry in the cache with the default time to live.
|
<T extends V> |
putWithErrors(K key,
T data)
Store an entry in the cache with the default time to live.
|
void |
setDefaultTtl(long defaultTTL)
Sets the default time to live for cache entries.
|
static final long UNLIMITED_IDLE_TIME
<T extends V> T put(K key, T data)
putWithErrors(Object, Object) if you want to handle them.key - A unique identifier.data - The data to store. Make sure that you don't alter the data after it has been put
to cache as (depending on the implementation) this might lead to altering the
entry in the cache. Use the returned data instead.<T extends V> T putWithErrors(K key, T data) throws CacheException
key - A unique identifier.data - The data to store. Make sure that you don't alter the data after it has been put
to cache as (depending on the implementation) this might lead to altering the
entry in the cache. Use the returned data instead.CacheException - Thrown on any errors encountered, supposed to include the stacktrace (if any).<T extends V> T get(K key)
getWithErrors(Object) if you want to handle them.key - The unique key under which the entry was stored.<T extends V> T getWithErrors(K key) throws CacheException
key - The unique key under which the entry was stored.CacheException - Thrown on any errors encountered, supposed to include the stacktrace (if any).MetaData getMetaData(K key) throws CacheException
MetaData of a cached entry if it is available.key - The key under which the entry was stored.MetaData of the entry if found, null otherwise.CacheException - Thrown on any errors encountered, supposed to include the stacktrace (if any).long getDefaultTtl()
void setDefaultTtl(long defaultTTL)
defaultTTL - The default time to live for a cache entry in milliseconds.long getDefaultMaxIdleTime()
void delete(K key) throws CacheException
key - The key under which the entry was stored.CacheException - Thrown on any errors encountered, supposed to include the stacktrace (if any).void cleanUp()
throws CacheException
CacheException - Thrown on any errors encountered, supposed to include the stacktrace (if any).String getName()
CacheStatistics getStatistics()
Copyright © 2013 dontdrinkandroot. All Rights Reserved.