|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap<K,V>
net.sourceforge.rcache.BaseCache<K,V>
net.sourceforge.rcache.WeakCache<K,V>
K
- the type of keys maintained by this cacheV
- the type of cached valuespublic class WeakCache<K,V>
Memory-Sensitive Cache Based on WeakReferences
Entries in a WeakCache will be garbage collected as soon as there are no hard references left.
For certain applications, this garbage collection policy may be too
aggressive, and it may be preferable to keep objects in memory until
there is really a need to free space. For those cases, SoftCache
will be a more sensible option.
WeakReference
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 | |
---|---|
WeakCache()
Default constructor. |
|
WeakCache(int initialCapacity)
Creates an instance with a custom initial capacity. |
|
WeakCache(int initialCapacity,
float loadFactor)
Creates an instance with a custom initial capacity and load factor. |
|
WeakCache(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 WeakCache()
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 WeakCache(int initialCapacity)
Creates an instance with a custom initial capacity.
initialCapacity
- The map initial capacitypublic WeakCache(int initialCapacity, float loadFactor)
Creates an instance with a custom initial capacity and load factor.
initialCapacity
- The map initial capacityloadFactor
- The map load factorpublic WeakCache(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 |