|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface Cache<K,V>
Interface that defines the common cache operations. Note: Due to the generic use of caching, it is recommended that implementations allow storage of null values (for example to cache methods that return null).
| Method Summary | |
|---|---|
void |
clear()
Removes all mappings from the cache. |
boolean |
containsKey(Object key)
Returns true if this cache contains a mapping for the specified key. |
V |
get(Object key)
Returns the value to which this cache maps the specified key. |
String |
getName()
Returns the cache name. |
Object |
getNativeCache()
Returns the the native, underlying cache provider. |
V |
put(K key,
V value)
Associates the specified value with the specified key in this cache (optional operation). |
V |
putIfAbsent(K key,
V value)
If the specified key is not already associated with a value, associate it with the given value. |
V |
remove(Object key)
Removes the mapping for this key from this cache if it is present (optional operation). |
boolean |
remove(Object key,
Object value)
Remove entry for key only if currently mapped to given value. |
V |
replace(K key,
V value)
Replace entry for key only if currently mapped to some value. |
boolean |
replace(K key,
V oldValue,
V newValue)
Replace entry for key only if currently mapped to given value. |
| Method Detail |
|---|
String getName()
Object getNativeCache()
boolean containsKey(Object key)
key - key whose presence in this cache is to be tested.
V get(Object key)
More formally, if this cache contains a mapping from a key k to a value v such that (key==null ? k==null : key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)
key - key whose associated value is to be returned.
containsKey(Object)
V put(K key,
V value)
m.containsKey(k) would return
true.))
key - key with which the specified value is to be associated.value - value to be associated with the specified key.
V putIfAbsent(K key,
V value)
if (!cache.containsKey(key))
return cache.put(key, value);
else
return cache.get(key);
key - key with which the specified value is to be associated.value - value to be associated with the specified key.
V remove(Object key)
(key==null ? k==null : key.equals(k)), that mapping
is removed. (The cache can contain at most one such mapping.)
Returns the value to which the cache previously associated the key, or null if the cache contained no mapping for this key. (A null return can also indicate that the cache previously associated null with the specified key if the implementation supports null values.) The cache will not contain a mapping for the specified key once the call returns.
key - key whose mapping is to be removed from the cache.
boolean remove(Object key,
Object value)
if ((cache.containsKey(key) && cache.get(key).equals(value)) {
cache.remove(key);
return true;
}
else
return false;
key - key with which the specified value is associated.value - value associated with the specified key.
boolean replace(K key,
V oldValue,
V newValue)
if ((cache.containsKey(key) && cache.get(key).equals(oldValue)) {
cache.put(key, newValue);
return true;
} else return false;
key - key with which the specified value is associated.oldValue - value expected to be associated with the specified key.newValue - value to be associated with the specified key.
V replace(K key,
V value)
if ((cache.containsKey(key)) {
return cache.put(key, value);
} else return null;
except that the action is performed atomically.
key - key with which the specified value is associated.value - value to be associated with the specified key.
void clear()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||