org.gjt.rec.cache
Class FixedCache

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

public class FixedCache
extends MapCache
implements Cache

FixedCache is an implementation of the Cache interface that uses a fixed size element store, so that the heap usage is always capped.

Author:
Neil Stockbridge
See Also:
Cache, CacheElementSource

Nested Class Summary
 
Nested classes inherited from class org.gjt.rec.cache.MapCache
MapCache.MapType
 
Field Summary
static String REVISION
           
 
Constructor Summary
FixedCache(int fixedSize)
          Constructs a FixedCache that refers to its elements using weak references.
FixedCache(int fixedSize, CacheElementSource src)
          Constructs a FixedCache that refers to its elements using weak references.
FixedCache(int fixedSize, MapCache.MapType type)
          Constructs a FixedCache that refers to its elements in a particular manner.
FixedCache(int fixedSize, MapCache.MapType type, CacheElementSource src)
          Constructs a FixedCache that refers to its elements in a particular manner.
 
Method Summary
 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.
 String toString()
           
 
Methods inherited from class org.gjt.rec.cache.MapCache
elementCount, hitCount, requestCount, resetStatistics
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.gjt.rec.cache.Cache
elementCount, hitCount, requestCount, resetStatistics
 

Field Detail

REVISION

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

FixedCache

public FixedCache(int fixedSize)
Constructs a FixedCache that refers to its elements using weak references.

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

FixedCache

public FixedCache(int fixedSize,
                  MapCache.MapType type)
Constructs a FixedCache that refers to its elements in a particular manner.

Parameters:
fixedSize - the maximum number of elements to hold in the cache.
type - if this argument is MapCache.MapType.WEAK, this cache will refer to its elements using weak references. if the argument is MapCache.MapType.STRONG, strong references will be used instead.

FixedCache

public FixedCache(int fixedSize,
                  CacheElementSource src)
Constructs a FixedCache that refers to its elements using weak references. Cache elements will be obtained 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.

FixedCache

public FixedCache(int fixedSize,
                  MapCache.MapType type,
                  CacheElementSource src)
Constructs a FixedCache that refers to its elements in a particular manner. Cache elements will be obtained from the supplied CacheElementSource.

Parameters:
fixedSize - the maximum number of elements to hold in the cache.
type - if this argument is MapCache.MapType.WEAK, this cache will refer to its elements using weak references. if the argument is MapCache.MapType.STRONG, strong references will be used instead.
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
Overrides:
lookup in class MapCache
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
Overrides:
put in class MapCache
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
Overrides:
invalidate in class MapCache
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
Overrides:
invalidateAll in class MapCache

toString

public String toString()
Overrides:
toString in class MapCache