|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.rcache.decorator.MruGuard<K,V>
K
- the type of keys maintained by this cacheV
- the type of cached valuespublic final class MruGuard<K,V>
Decorator for Cache instances that adds an MRU list containing hard references to the most recently used entries.
This decorator prevents the most recently used entries from being garbage collected.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface net.sourceforge.rcache.Cache |
---|
Cache.Operation |
Field Summary |
---|
Fields inherited from interface net.sourceforge.rcache.Cache |
---|
DEFAULT_CONCURRENCY_LEVEL, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR |
Constructor Summary | |
---|---|
MruGuard(Cache<K,V> cache,
int mruSize)
Creates an instance. |
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. |
int |
getMaxSize()
Gets the maximum size of the MRU list. |
protected java.util.Iterator<V> |
mruIterator()
Gets an iterator for the internal MRU list. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MruGuard(Cache<K,V> cache, int mruSize)
cache
- The cache instance to wrapmruSize
- The number of items to maintain in the MRU listMethod Detail |
---|
public 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
.
get
in interface Cache<K,V>
key
- key whose associated value is to be returned.
public 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
.
put
in interface Cache<K,V>
key
- key with which the specified value is to be associated.value
- value to be associated with the specified key.
public 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
.
remove
in interface Cache<K,V>
key
- key whose entry is to be removed from the cache.
public 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.
clear
in interface Cache<K,V>
public int getMaxSize()
protected java.util.Iterator<V> mruIterator()
This method is for test purposes only.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |