|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.xorm.cache.LRUCache
An LRU Cache with a hard and soft reference limit. Objects that exceed the hard limit are stored as soft references, and objects that exceed the soft limit are discarded from the cache. The hard limit and soft limit are additive, in that hard limit is the number of objects to store with hard references, and the soft limit is the number of objects to store with soft references, exclusive of the hard limit. Hence, a hard limit of 10, and soft limit of 20 would create a (possible) cache size of 30. Since items stored as soft references are subject to collection by the Garbage collector, the soft reference cache will often be smaller than the limit set on it. It is possible to also configure the cache to behave as only a soft or hard cache by simply configuring the hard and soft limit appropriately. See the additional documentation below about how to configure this. This class uses a referenceQueue to insure that values removed from the This class can also be configured to log its statistics to its logger (defined as Logger.getLogger("org.xorm.cache.LRUCache")) Normally, this class would be used by adding the following properties to the properties files given to xorm at startup:
Field Summary | |
static int |
DEFAULT_HARD_SIZE
|
static long |
DEFAULT_LOG_INTERVAL
|
static int |
DEFAULT_SOFT_SIZE
|
Constructor Summary | |
LRUCache()
Construct an LRUCache using DEFAULT_HARD_SIZE, DEFAULT_SOFT_SIZE, and DEFAULT_LOG_INTERVAL. |
|
LRUCache(int hardSize,
int softSize,
long aLogInterval)
Construct a LRUCache. |
Method Summary | |
void |
add(Row row)
Adds or replaces the Row in the cache. |
void |
addAll(Collection c)
Optional method to add a collection of objects to the cache all at once. |
Row |
get(Table table,
Object aPrimaryKey)
Retrieves a cloned copy of the Row from the cache with the matching primary key. |
void |
log()
Optional method for use by external classes to force logging of the cache usage statistics regardless of the value of logInterval. |
void |
remove(Row row)
Removes a Row from the cache by its primary key. |
Object |
removeValue(Object value)
Optional method to remove a value from the cache. |
void |
setFactory(InterfaceManagerFactory factory)
|
void |
setProperties(Properties props)
This method is called by XORM after reflectively instantiating the class. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int DEFAULT_HARD_SIZE
public static final int DEFAULT_SOFT_SIZE
public static final long DEFAULT_LOG_INTERVAL
Constructor Detail |
public LRUCache(int hardSize, int softSize, long aLogInterval)
hardSize
- The number of objects to keep hard references to. If
this number is greater than 0, keep references to that number of objects
with hard references. Objects that are discarded from the hard cache
will be put into soft cache, if soft cache does not have a size of 0.
If this value is 0, do not create a hard cache. An exception is thrown
if this value is less than 0.softSize
- The number of objects to keep soft references to. If
this number is greater than 0, keep references to that number of objects
with soft references. Objects that are discarded from the soft cache,
either through lack of space, or through garbage collection, are
discarded completely from the cache. If this value is 0, do not create a
soft cache. If this value is less than 0, the number of references
stored will be limited to the amount of memory in the system, and how
aggressive the garbage collector is.aLogInterval
- the amount of time in milliseconds to log usage
statistics to the logger ("org.xorm.cache.LRUCache"). If this value is
0, always log. If this value is a negative number, never log. If this
value is positive, log whenever that number of milliseconds has elapsed
and the cache is accessed. Logging is done on a best effort basis, and
does not use a background thread. Therefore, if the cache is not
accessed for time greater than the log interval, no values will be
logged.
RuntimeException
- if the hardSize is less than 0, or the
hardSize and softSize are both 0public LRUCache()
Method Detail |
public void setProperties(Properties props)
setProperties
in interface Configurable
props
- The Properties object (possibly) containing values to use
for hardSize, softSize, and logInterval.public void setFactory(InterfaceManagerFactory factory)
setFactory
in interface Configurable
public void add(Row row)
DataCache
add
in interface DataCache
public void addAll(Collection c)
c
- A Collection of rows to be added to the cache. The Rows will be
added in Iterator order.public Row get(Table table, Object aPrimaryKey)
get
in interface DataCache
public void log()
public Object removeValue(Object value)
public void remove(Row row)
DataCache
remove
in interface DataCache
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |