com.compoze.collab.util
Class SoftCache
java.lang.Object
java.lang.Thread
com.compoze.collab.util.SoftCache
- All Implemented Interfaces
- Runnable
public class SoftCache
- extends Thread
A class for caching values using SoftReference
s.
Values in the cache that are otherwise unused can be garbage collected.
A value of null
will be represented by an instance of
NullValue
.
Nested Class Summary |
static class |
SoftCache.NullValue
Used to represent null values in the cache. |
Constructor Summary |
SoftCache()
Create a SoftCache. |
Method Summary |
Object |
get(Object key)
Get the cached value, if any, for a key. |
Object |
put(Object key,
Object value)
Put a value for key in the cache. |
void |
run()
The code for the thread that cleans garbage-collected values from the
cache. |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
SoftCache
public SoftCache()
- Create a SoftCache.
get
public Object get(Object key)
- Get the cached value, if any, for a key. If there is no cached value, returns
null
. If the cached value is null
, returns an
instance of SoftCache.NullValue
.
- Parameters
key
- the key to look up
- Returns
- the cached value;
null
if no cached value;
an instance of NullValue
if the cached value is
null
put
public Object put(Object key,
Object value)
- Put a value for
key
in the cache. Returns the old value, if any.
- Parameters
key
- the hash key; cannot be null
value
- the value for key; can be null
- Returns
- previous value for key;
null
if none or if
the previous value has been cleared by the garbage collector;
an instance of NullValue
if the cached value is
null
run
public void run()
- The code for the thread that cleans garbage-collected values from the
cache. Do not call this method.
- Specified by:
run
in interface Runnable
- Overrides:
run
in class Thread
Copyright © 2006 BEA Systems, Inc. All Rights Reserved