public class WeakCache extends Object
The clean() method explicitly removes entries where the keys have been garbage collected.
A background thread is created to clean all existing WeakCache objects at regular intervals. The default interval is 1 minute, but this can be changed by calling setCleanInterval().
Modifier and Type | Field and Description |
---|---|
int |
cleanDelay
This is the time between a key being freed to when a clean() occurs.
|
Constructor and Description |
---|
WeakCache()
Constructs a new WeakCache with the default initial capacity
and a default load factor of 0.75
|
WeakCache(int initialCapacity)
Constructs a new WeakCache with the specified initial capacity
and a default load factor of 0.75
|
WeakCache(int initialCapacity,
float loadFactor) |
Modifier and Type | Method and Description |
---|---|
void |
clean()
Remove all entries for which the key has been garbage collected.
|
Object |
get(Object key) |
Object |
getKeyForValue(Object value)
Given a value, find the key associated with that value if present.
|
void |
put(Object key,
Object data) |
void |
remove(Object key) |
static void |
setCleanInterval(long interval)
Deprecated.
this is no longer used. Each WeakCache has its own cleaner
Thread that checks the reference queue for cleaning.
|
protected void |
valuesRemoved(Vector values)
This is called if a clean() call finds values to remove.
|
public int cleanDelay
public WeakCache()
public WeakCache(int initialCapacity)
public WeakCache(int initialCapacity, float loadFactor)
public static void setCleanInterval(long interval)
interval
- the interval in milliseconds. If this is less 1 then the default
value of 60000 (1 minute) will be used.public void clean()
protected void valuesRemoved(Vector values)
values
- the values that were removed.public Object getKeyForValue(Object value)
value
- the value to look for.public void remove(Object key)