TUM CCSM Commons

edu.tum.cs.commons.cache
Class SoftRefCacheBase<I,H,E,X extends java.lang.Exception>

java.lang.Object
  extended by edu.tum.cs.commons.cache.CacheBase<I,H,E,X>
      extended by edu.tum.cs.commons.cache.SoftRefCacheBase<I,H,E,X>
Type Parameters:
I - the index type of the cache
H - the hash map key type
E - the type stored in the cache
X - 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 java.lang.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

Field Summary
protected  java.util.HashMap<H,java.lang.ref.SoftReference<E>> cache
          The actual cache.
 
Constructor Summary
SoftRefCacheBase()
           
 
Method Summary
 E getItem(I identifier)
          Obtain an item from the cache.
static java.lang.String getStatistics()
          Returns a statistics string with information about cache hits and misses for debugging purposes.
 
Methods inherited from class edu.tum.cs.commons.cache.CacheBase
getHashKey, obtainItem
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected final java.util.HashMap<H,java.lang.ref.SoftReference<E>> cache
The actual cache.

Constructor Detail

SoftRefCacheBase

public SoftRefCacheBase()
Method Detail

getItem

public E getItem(I identifier)
          throws X extends java.lang.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 java.lang.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 java.lang.Exception

getStatistics

public static java.lang.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

TUM CCSM Commons - 2.7