| java.lang.Object org.xorm.cache.LRUCache
LRUCache | public class LRUCache implements DataCache(Code) | | 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:
- org.xorm.cache.DataCacheClass=org.xorm.cache.LRUCache
The following properties will override the default values in this class:
- org.xorm.cache.LRUCache.hardSize=<non-negative intValue>
- org.xorm.cache.LRUCache.softSize=<intValue>
- org.xorm.cache.LRUCache.logInterval=<intValue>
See setProperties for a description of the meaning of these properties.
author: Harry Evans |
Constructor Summary | |
public | LRUCache(int hardSize, int softSize, long aLogInterval) Construct a LRUCache. | public | LRUCache() Construct an LRUCache using DEFAULT_HARD_SIZE, DEFAULT_SOFT_SIZE, and
DEFAULT_LOG_INTERVAL. |
Method Summary | |
public void | add(Row row) | public void | addAll(Collection c) Optional method to add a collection of objects to the cache all at once.
Not currently used by xorm or defined by the xorm interface.
Parameters: c - A Collection of rows to be added to the cache. | public Row | get(Table table, Object aPrimaryKey) Retrieves a cloned copy of the Row from the cache with the
matching primary key. | public void | log() Optional method for use by external classes to force logging of the cache
usage statistics regardless of the value of logInterval. | public void | remove(Row row) | public Object | removeValue(Object value) Optional method to remove a value from the cache. | public void | setFactory(InterfaceManagerFactory factory) | public void | setProperties(Properties props) This method is called by XORM after reflectively instantiating the class. |
DEFAULT_HARD_SIZE | final public static int DEFAULT_HARD_SIZE(Code) | | |
DEFAULT_LOG_INTERVAL | final public static long DEFAULT_LOG_INTERVAL(Code) | | |
DEFAULT_SOFT_SIZE | final public static int DEFAULT_SOFT_SIZE(Code) | | |
LRUCache | public LRUCache(int hardSize, int softSize, long aLogInterval)(Code) | | Construct a LRUCache. This method is provided primarily for use when
programatically assigning the cache that XORM will use. The default
constructor is usually the one that gets used.
Parameters: hardSize - The number of objects to keep hard references to. Ifthis number is greater than 0, keep references to that number of objectswith hard references. Objects that are discarded from the hard cachewill 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 thrownif this value is less than 0. Parameters: softSize - The number of objects to keep soft references to. Ifthis number is greater than 0, keep references to that number of objectswith soft references. Objects that are discarded from the soft cache,either through lack of space, or through garbage collection, arediscarded completely from the cache. If this value is 0, do not create asoft cache. If this value is less than 0, the number of referencesstored will be limited to the amount of memory in the system, and howaggressive the garbage collector is. Parameters: aLogInterval - the amount of time in milliseconds to log usagestatistics to the logger ("org.xorm.cache.LRUCache"). If this value is0, always log. If this value is a negative number, never log. If thisvalue is positive, log whenever that number of milliseconds has elapsedand the cache is accessed. Logging is done on a best effort basis, anddoes not use a background thread. Therefore, if the cache is notaccessed for time greater than the log interval, no values will belogged. throws: RuntimeException - if the hardSize is less than 0, or thehardSize and softSize are both 0 |
LRUCache | public LRUCache()(Code) | | Construct an LRUCache using DEFAULT_HARD_SIZE, DEFAULT_SOFT_SIZE, and
DEFAULT_LOG_INTERVAL. This constructor is provided to enable reflective
instantiation of the cache. It is normally used in combination with a
call to setProperties, which will result in the cache extracting
(possibly) different values than the default with which to run.
|
addAll | public void addAll(Collection c)(Code) | | Optional method to add a collection of objects to the cache all at once.
Not currently used by xorm or defined by the xorm interface.
Parameters: c - A Collection of rows to be added to the cache. The Rows will beadded in Iterator order. |
get | public Row get(Table table, Object aPrimaryKey)(Code) | | Retrieves a cloned copy of the Row from the cache with the
matching primary key.
|
log | public void log()(Code) | | Optional method for use by external classes to force logging of the cache
usage statistics regardless of the value of logInterval.
|
removeValue | public Object removeValue(Object value)(Code) | | Optional method to remove a value from the cache. Since all objects removed are Rows, this method should not be called directly in the near future.
|
setProperties | public void setProperties(Properties props)(Code) | | This method is called by XORM after reflectively instantiating the class.
This method looks for the following properties:
- org.xorm.cache.LRUCache.hardSize
- org.xorm.cache.LRUCache.softSize
- org.xorm.cache.LRUCache.logInterval
Any property that isn't found will have the class default value assigned
to it.
Parameters: props - The Properties object (possibly) containing values to usefor hardSize, softSize, and logInterval. |
|
|