org.apache.camel.util
Class LRUSoftCache<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<K,V>
          extended by java.util.LinkedHashMap<K,V>
              extended by org.apache.camel.util.LRUCache<K,V>
                  extended by org.apache.camel.util.LRUSoftCache<K,V>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,V>, Service
Direct Known Subclasses:
EndpointRegistry

public class LRUSoftCache<K,V>
extends LRUCache<K,V>

A Least Recently Used Cache which uses SoftReference.

This implementation uses SoftReference for stored values in the cache, to support the JVM when it wants to reclaim objects when its running out of memory. Therefore this implementation does not support all the Map methods.

The following methods is only be be used:

The LinkedHashMap.containsValue(Object) method should not be used as it's not adjusted to check for the existence of a value without catering for the soft references.

See Also:
LRUCache, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
LRUSoftCache(int maximumCacheSize)
           
LRUSoftCache(int initialCapacity, int maximumCacheSize, float loadFactor, boolean accessOrder)
           
 
Method Summary
 boolean containsKey(Object o)
           
 Set<Map.Entry<K,V>> entrySet()
           
 V get(Object o)
           
 boolean isEmpty()
           
 Set<K> keySet()
           
 V put(K key, V value)
           
 void putAll(Map<? extends K,? extends V> map)
           
 V remove(Object o)
           
 int size()
           
 String toString()
           
 Collection<V> values()
           
 
Methods inherited from class org.apache.camel.util.LRUCache
getHits, getMaxCacheSize, getMisses, removeEldestEntry, resetStatistics, start, stop
 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue
 
Methods inherited from class java.util.HashMap
clone
 
Methods inherited from class java.util.AbstractMap
equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

LRUSoftCache

public LRUSoftCache(int maximumCacheSize)

LRUSoftCache

public LRUSoftCache(int initialCapacity,
                    int maximumCacheSize,
                    float loadFactor,
                    boolean accessOrder)
Method Detail

put

public V put(K key,
             V value)
Specified by:
put in interface Map<K,V>
Overrides:
put in class HashMap<K,V>

get

public V get(Object o)
Specified by:
get in interface Map<K,V>
Overrides:
get in class LRUCache<K,V>

putAll

public void putAll(Map<? extends K,? extends V> map)
Specified by:
putAll in interface Map<K,V>
Overrides:
putAll in class HashMap<K,V>

remove

public V remove(Object o)
Specified by:
remove in interface Map<K,V>
Overrides:
remove in class HashMap<K,V>

values

public Collection<V> values()
Specified by:
values in interface Map<K,V>
Overrides:
values in class HashMap<K,V>

size

public int size()
Specified by:
size in interface Map<K,V>
Overrides:
size in class HashMap<K,V>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K,V>
Overrides:
isEmpty in class HashMap<K,V>

containsKey

public boolean containsKey(Object o)
Specified by:
containsKey in interface Map<K,V>
Overrides:
containsKey in class HashMap<K,V>

keySet

public Set<K> keySet()
Specified by:
keySet in interface Map<K,V>
Overrides:
keySet in class HashMap<K,V>

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>
Overrides:
entrySet in class HashMap<K,V>

toString

public String toString()
Overrides:
toString in class LRUCache<K,V>


Apache CAMEL