|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
K
- the type of keys maintained by this cacheV
- the type of cached valuespublic interface Cache<K,V>
Memory-Sensitive Cache.
Cache implementations will probably be implemented as Maps and so, this
interface is maintained "compatible" with Map
. However,
in most situations, the Map interface is more complex than needed.
This interface offers a simpler option, more oriented to the actual goals of a Cache.
Nested Class Summary | |
---|---|
static class |
Cache.Operation
The operations defined in the Cache interface. |
Field Summary | |
---|---|
static int |
DEFAULT_CONCURRENCY_LEVEL
Default concurrency level. |
static int |
DEFAULT_INITIAL_CAPACITY
Default cache initial capacity. |
static float |
DEFAULT_LOAD_FACTOR
Default cache load factor. |
Method Summary | |
---|---|
void |
clear()
Removes all entries from this cache. |
V |
get(java.lang.Object key)
Returns the value to which this cache maps the specified key. |
V |
put(K key,
V value)
Associates the specified value with the specified key in this cache, but only if no value is associated yet. |
V |
remove(java.lang.Object key)
Removes the entry for this key from this cache if present. |
Field Detail |
---|
static final int DEFAULT_INITIAL_CAPACITY
static final float DEFAULT_LOAD_FACTOR
static final int DEFAULT_CONCURRENCY_LEVEL
Method Detail |
---|
V get(java.lang.Object key)
Returns the value to which this cache maps the specified key. Returns null if the cache contains no entry for this key. A return value of null does not necessarily indicate that the cache contains no entry for the key; it's also possible that the cache explicitly maps the key to null
.Although this method should use K for the key type, it
is left as Object to keep this interface compatible with
Map
.
key
- key whose associated value is to be returned.
V put(K key, V value)
Associates the specified value with the specified key in this cache, but only if no value is associated yet. If the cache previously contained an entry for this key, the old value is returned, but not replaced.
This method is equivalent to the putIfAbsent from the
ConcurrentMap
class, as it is more
appropriate for a cache than the original one from Map
.
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
java.lang.ClassCastException
- if the class of the specified key or value
prevents it from being stored in this cache.
java.lang.IllegalArgumentException
- if some aspect of this key or value
prevents it from being stored in this map.V remove(java.lang.Object key)
Removes the entry for this key from this cache if present.
Although this method should use K for the key type, it
is left as Object to keep this interface compatible with
Map
.
key
- key whose entry is to be removed from the cache.
void clear()
Removes all entries from this cache.
This method must be handled very carefully, as it will break the assumption of unique instances for cached factories.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |