|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractMap<K,V> net.sourceforge.rcache.BaseCache<K,V> net.sourceforge.rcache.SoftCache<K,V>
K
- the type of keys maintained by this cacheV
- the type of cached valuespublic class SoftCache<K,V>
Memory-Sensitive Cache Based on SoftReferences
Entries in a SoftCache can be garbage collected if, and only if, the JVM considers that more memory is needed. This means that all SoftCache instances will be effectively cleared before an OutOfMemory error is thrown.
For certain applications, this class may be too much memory-consuming. If
the programmer only needs to enforce that a single instance is used for a
given key, and it is not important to keep this instance afterwards,
WeakCache
may be a better option.
SoftReference
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
Nested classes/interfaces inherited from interface net.sourceforge.rcache.Cache |
---|
Cache.Operation |
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Field Summary |
---|
Fields inherited from interface net.sourceforge.rcache.Cache |
---|
DEFAULT_CONCURRENCY_LEVEL, DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR |
Constructor Summary | |
---|---|
SoftCache()
Default constructor. |
|
SoftCache(int initialCapacity)
Creates an instance with a custom initial capacity. |
|
SoftCache(int initialCapacity,
float loadFactor)
Creates an instance with a custom initial capacity and load factor. |
|
SoftCache(int initialCapacity,
float loadFactor,
int concurrencyLevel)
Creates an instance with custom capacity and concurrency level. |
Method Summary | |
---|---|
protected KeyedReference<K,V> |
createRef(K key,
V value,
java.lang.ref.ReferenceQueue<V> queue)
Factory method for creating a new reference instance. |
Methods inherited from class net.sourceforge.rcache.BaseCache |
---|
clear, entrySet, equals, get, hashCode, purge, put, remove, size, values |
Methods inherited from class java.util.AbstractMap |
---|
clone, containsKey, containsValue, isEmpty, keySet, putAll, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SoftCache()
Default constructor.
Instances created with this constructor will have a small initial capacity and a highly restricted concurrency level.
For concurrent maps, resizing is a costly operation. Whenever possible, it is advised to specify the expected maximum size, in order to minimise the number of resizes.
public SoftCache(int initialCapacity)
Creates an instance with a custom initial capacity.
initialCapacity
- The map initial capacitypublic SoftCache(int initialCapacity, float loadFactor)
Creates an instance with a custom initial capacity and load factor.
initialCapacity
- The map initial capacityloadFactor
- The map load factorpublic SoftCache(int initialCapacity, float loadFactor, int concurrencyLevel)
Creates an instance with custom capacity and concurrency level.
The concurrency level is used as a hint to select the internal Map implementation:
HashMap
will be used.Hashtable
will be selected.ConcurrentHashMap
will be
created with the specified concurrency level.
initialCapacity
- The map initial capacityloadFactor
- The map load factorconcurrencyLevel
- The concurrency level.Method Detail |
---|
protected final KeyedReference<K,V> createRef(K key, V value, java.lang.ref.ReferenceQueue<V> queue)
createRef
in class BaseCache<K,V>
key
- The keyvalue
- The valuequeue
- A reference queue
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |