org.gjt.rec.cache
Class TagCache

java.lang.Object
  |
  +--org.gjt.rec.cache.TagCache
All Implemented Interfaces:
Cache

public class TagCache
extends Object
implements Cache

TagCache is an implementation of the Cache interface that offers cacheing for the fewest bytecode instructions at the cost of the hit ratio. A TagCache uses a fixed size element store, so that the heap usage is always capped. This implementation uses only strong references.

Author:
Neil Stockbridge
See Also:
Cache, CacheElementSource

Field Summary
static String REVISION
           
 
Constructor Summary
TagCache(int fixedSize)
          Constructs a TagCache.
TagCache(int fixedSize, CacheElementSource src)
          Constructs a TagCache that will be obtain its elements from the supplied CacheElementSource.
 
Method Summary
 int elementCount()
           
 int hitCount()
           
 void invalidate(Object id)
          Invalidates the entry in this cache with a particular id.
 void invalidateAll()
          Invalidates all entries in this cache.
 Object lookup(Object id)
          Tries to find an element with a particular id in this cache.
 void put(Object id, Object element)
          Puts a particular element in this cache associated with a particular id.
 int requestCount()
           
 void resetStatistics()
          Resets the cache performance statistics to the values as they were when the cache was created.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
See Also:
Constant Field Values
Constructor Detail

TagCache

public TagCache(int fixedSize)
Constructs a TagCache.

Parameters:
fixedSize - the maximum number of elements to hold in the cache.

TagCache

public TagCache(int fixedSize,
                CacheElementSource src)
Constructs a TagCache that will be obtain its elements from the supplied CacheElementSource.

Parameters:
fixedSize - the maximum number of elements to hold in the cache.
src - the element source from which the cache will obtain its elements in the event of a cache miss.
Method Detail

lookup

public Object lookup(Object id)
Description copied from interface: Cache
Tries to find an element with a particular id in this cache.

Specified by:
lookup in interface Cache
Parameters:
id - the id of the desired element.
Returns:
the element corresponding to the supplied id or null if no such element could be found.

put

public void put(Object id,
                Object element)
Description copied from interface: Cache
Puts a particular element in this cache associated with a particular id. Note that invoking this method does not guarantee that the element will stay in the cache even long enough to be returned by a subsequent invocation of the lookup(Object) method.

Specified by:
put in interface Cache
Parameters:
id - the id associated with the supplied element.
element - the element to store in the cache.

invalidate

public void invalidate(Object id)
Description copied from interface: Cache
Invalidates the entry in this cache with a particular id.

Specified by:
invalidate in interface Cache
Parameters:
id - the id corresponding to the element to invalidate.

invalidateAll

public void invalidateAll()
Description copied from interface: Cache
Invalidates all entries in this cache.

Specified by:
invalidateAll in interface Cache

elementCount

public int elementCount()
Specified by:
elementCount in interface Cache
Returns:
the number of elements in this cache. this number is the actual number of elements cached, not the size of the element store.

requestCount

public int requestCount()
Specified by:
requestCount in interface Cache
Returns:
the number of cache requests made of this cache.

hitCount

public int hitCount()
Specified by:
hitCount in interface Cache
Returns:
the number of cache requests that have been satisfied by this cache.

resetStatistics

public void resetStatistics()
Description copied from interface: Cache
Resets the cache performance statistics to the values as they were when the cache was created.

Specified by:
resetStatistics in interface Cache

toString

public String toString()
Overrides:
toString in class Object