edu.tum.cs.commons.cache
Class SoftRefCacheBase<I,H,E,X extends Exception>
java.lang.Object
edu.tum.cs.commons.cache.CacheBase<I,H,E,X>
edu.tum.cs.commons.cache.SoftRefCacheBase<I,H,E,X>
- Type Parameters:
I - the index type of the cacheH - the hash map key typeE - the type stored in the cacheX - the type of exception thrown by the CacheBase.obtainItem(Object)
method. Use the NeverThrownRuntimeException if no
exception will be thrown.
- Direct Known Subclasses:
- SoftRefStraightCacheBase
public abstract class SoftRefCacheBase<I,H,E,X extends Exception>
- extends CacheBase<I,H,E,X>
A base class for dynamic caches based on SoftReferences. If
identifiers itself are suitable hash keys, use class
SoftRefStraightCacheBase.
The implementation is memory-sensitive, i.e. it dynamically removes entries
from the cache if the virtual machine is short on memory. However, this
dynamic is completely transparent to the user.
Note: To make this cache efficient the virtual machine must work in
server mode.
- Version:
- $Rev: 26268 $
- Author:
- Florian Deissenboeck, Tilman Seifert, $Author: juergens $
- Rating:
- GREEN Hash: A74130243CAE0E00D2C6A51DDFEA68A0
|
Method Summary |
E |
getItem(I identifier)
Obtain an item from the cache. |
static String |
getStatistics()
Returns a statistics string with information about cache hits and misses
for debugging purposes. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
cache
protected final HashMap<H,SoftReference<E>> cache
- The actual cache.
SoftRefCacheBase
public SoftRefCacheBase()
getItem
public E getItem(I identifier)
throws X extends Exception
- Obtain an item from the cache. If the item was not cached yet, it will be
cached.
- Specified by:
getItem in class CacheBase<I,H,E,X extends Exception>
- Parameters:
identifier - an object identifying the item to retrieve from the cache.
This class' implementation works with a hash map so
identifiers must adhere to the conventions for
Object.hashcode().
- Returns:
- The item.
- Throws:
X extends Exception
getStatistics
public static String getStatistics()
- Returns a statistics string with information about cache hits and misses
for debugging purposes. As this is implemented in a static way results
are only valid if only a single instance of the specific cache class
exists.
TUM CCSM Commons - 2.7