|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
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>
A cache is a component that transparently stores data so that future requests for that data can be served faster. Usually caches are used to "remember" the results of computationally complex operations or to speed up the access to a slow medium. The general approach is to ask the cache if it has the result available, if yes then return the stored result, if not, compute the result and store it in the cache. Caches are usually chosen to have a (much) smaller size than the amount of the overall available data, so strategies come into play how entries are evicted when the cache size becomes to large. Therefore caches are not "reliable" as one might expect from a persistent storage: when an entries is stored in the cache, there is no guarantee that it is still available on the next get. Cache entries can also have a time to live which means that even if the entry is available after its expiration it is discarded in favor of new data.
| Field Summary | |
|---|---|
static long |
UNLIMITED_IDLE_TIME
|
| Method Summary | ||
|---|---|---|
void |
cleanUp()
Cleanup the cache. |
|
void |
delete(K key)
Manually remove an entry from the cache. |
|
|
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. |
|
|
getWithErrors(K key)
Retrieve an entry from the cache if it is available. |
|
|
put(K key,
T data)
Store an entry in the cache with the default time to live. |
|
|
putWithErrors(K key,
T data)
Store an entry in the cache with the default time to live. |
|
| Field Detail |
|---|
static final long UNLIMITED_IDLE_TIME
| Method Detail |
|---|
<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()
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()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||