org.shiftone.cache.decorator.soft
Class SoftCache
java.lang.Object
org.shiftone.cache.decorator.soft.SoftCache
- All Implemented Interfaces:
- Cache, ReapableCache
- public class SoftCache
- extends java.lang.Object
- implements Cache, ReapableCache
Memory sensitive cache.
This cache implementation proxies to a cache that was passed to it's constructor.
When objects are added to the cache, the object wrapped in a SoftReference,
and then the Reference is added to the delegate cache.
Once a SoftCache is created for a cache, the SoftCache should always be used to
access this cache. Using the original cache directly is not recommended.
Note that there are no guarantees as to how long objects you put in cache will remain
there. This is entirely at the digression of the garbage collector, which tends to
be hasty about freeing up memory.
- Version:
- $Revision: 1.8 $
- Author:
- Jeff Drost
Method Summary |
void |
addObject(java.lang.Object key,
java.lang.Object cacheObject)
adds an object to the cache |
void |
clear()
Removes ALL keys and values from the cache. |
java.lang.Object |
getObject(java.lang.Object key)
Gets a soft reference out of the underlying cache implementation, and then
returns the value held by the reference. |
void |
remove(java.lang.Object key)
remove a specific key/value pair from the cache |
void |
removeExpiredElements()
Cleans all cache elements out that have had their objects collected by the GC. |
int |
size()
The number of key/value pares in the cache |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
SoftCache
public SoftCache(Cache cache)
addObject
public void addObject(java.lang.Object key,
java.lang.Object cacheObject)
- Description copied from interface:
Cache
- adds an object to the cache
- Specified by:
addObject
in interface Cache
getObject
public java.lang.Object getObject(java.lang.Object key)
- Gets a soft reference out of the underlying cache implementation, and then
returns the value held by the reference.
- Specified by:
getObject
in interface Cache
remove
public final void remove(java.lang.Object key)
- Description copied from interface:
Cache
- remove a specific key/value pair from the cache
- Specified by:
remove
in interface Cache
size
public final int size()
- Description copied from interface:
Cache
- The number of key/value pares in the cache
- Specified by:
size
in interface Cache
clear
public final void clear()
- Description copied from interface:
Cache
- Removes ALL keys and values from the cache.
Use with digression. Using this method too frequently
may defeat the purpose of caching.
- Specified by:
clear
in interface Cache
removeExpiredElements
public void removeExpiredElements()
- Cleans all cache elements out that have had their objects collected by the GC.
- Specified by:
removeExpiredElements
in interface ReapableCache
toString
public final java.lang.String toString()