com.ibatis.sqlmap.engine.cache

Class CacheModel

public class CacheModel extends Object implements ExecuteListener

Wrapper for Caches.
Field Summary
static ObjectNULL_OBJECT
This is used to represent null objects that are returned from the cache so that they can be cached, too.
Constructor Summary
CacheModel()
Default constructor
Method Summary
voidaddFlushTriggerStatement(String statementName)
Adds a flushTriggerStatment.
voidconfigure(Properties props)
Configures the cache
voidflush()
Clears the cache
longgetFlushInterval()
Getter for flushInterval property
longgetFlushIntervalSeconds()
Getter for flushInterval property
IteratorgetFlushTriggerStatementNames()
Gets an Iterator containing all flushTriggerStatment objects for this cache.
doublegetHitRatio()
Returns statistical information about the cache.
StringgetId()
Getter for the cache model's id
protected intgetMaxObjectLogSize()
Get the maximum size of an object in the log output.
ObjectgetObject(CacheKey key)
Get an object out of the cache.
StringgetResource()
Getter for resource property
booleanisReadOnly()
Getter for read-only property
booleanisSerialize()
Getter to tell if the cache serializes
protected voidlog(String action, boolean addValue, Object cacheValue)
Log a cache action.
voidonExecuteStatement(MappedStatement statement)
ExecuteListener event.
voidputObject(CacheKey key, Object value)
Add an object to the cache
voidsetCacheController(CacheController controller)
Sets up the controller for the cache model
voidsetControllerProperties(Properties cacheProps)
voidsetFlushInterval(long flushInterval)
Setter for flushInterval property
voidsetId(String id)
Setter for the cache model's id
voidsetReadOnly(boolean readOnly)
Setter for read-only property
voidsetResource(String resource)
Setter for resource property
voidsetSerialize(boolean serialize)
Setter to tell the cache to serialize objects

Field Detail

NULL_OBJECT

public static final Object NULL_OBJECT
This is used to represent null objects that are returned from the cache so that they can be cached, too.

Constructor Detail

CacheModel

public CacheModel()
Default constructor

Method Detail

addFlushTriggerStatement

public void addFlushTriggerStatement(String statementName)
Adds a flushTriggerStatment. When a flushTriggerStatment is executed, the cache is flushed (cleared).

Parameters: statementName The statement to add.

configure

public void configure(Properties props)
Configures the cache

Parameters: props

flush

public void flush()
Clears the cache

getFlushInterval

public long getFlushInterval()
Getter for flushInterval property

Returns: The flushInterval (in milliseconds)

getFlushIntervalSeconds

public long getFlushIntervalSeconds()
Getter for flushInterval property

Returns: The flushInterval (in milliseconds)

getFlushTriggerStatementNames

public Iterator getFlushTriggerStatementNames()
Gets an Iterator containing all flushTriggerStatment objects for this cache.

Returns: The Iterator

getHitRatio

public double getHitRatio()
Returns statistical information about the cache.

Returns: the number of cache hits divided by the total requests

getId

public String getId()
Getter for the cache model's id

Returns: the id

getMaxObjectLogSize

protected int getMaxObjectLogSize()
Get the maximum size of an object in the log output.

Returns: Maximum size of a logged object in the output

getObject

public Object getObject(CacheKey key)
Get an object out of the cache. A side effect of this method is that is may clear the cache if it has not been cleared in the flushInterval.

Parameters: key The key of the object to be returned

Returns: The cached object (or null)

getResource

public String getResource()
Getter for resource property

Returns: the value of the resource property

isReadOnly

public boolean isReadOnly()
Getter for read-only property

Returns: true if a read-only model

isSerialize

public boolean isSerialize()
Getter to tell if the cache serializes

Returns: true if the cache model serializes objects

log

protected void log(String action, boolean addValue, Object cacheValue)
Log a cache action. Since this method is pretty heavy weight, it's best to enclose it with a log.isDebugEnabled() when called.

Parameters: action String to output addValue Add the value being cached to the log cacheValue The value being logged

onExecuteStatement

public void onExecuteStatement(MappedStatement statement)
ExecuteListener event. This will be called by a MappedStatement for which this cache is registered as a ExecuteListener. It will be called each time an executeXXXXXX method is called. In the case of the Cache class, it is registered in order to flush the cache whenever a certain statement is executed. (i.e. the flushOnExecute cache policy)

Parameters: statement The statement to execute

putObject

public void putObject(CacheKey key, Object value)
Add an object to the cache

Parameters: key The key of the object to be cached value The object to be cached

setCacheController

public void setCacheController(CacheController controller)
Sets up the controller for the cache model

Throws: ClassNotFoundException - if the class cannot be found InstantiationException - if the class cannot be instantiated IllegalAccessException - if the classes constructor is not accessible

setControllerProperties

public void setControllerProperties(Properties cacheProps)

setFlushInterval

public void setFlushInterval(long flushInterval)
Setter for flushInterval property

Parameters: flushInterval The new flushInterval (in milliseconds)

setId

public void setId(String id)
Setter for the cache model's id

Parameters: id - the new id

setReadOnly

public void setReadOnly(boolean readOnly)
Setter for read-only property

Parameters: readOnly - the new setting

setResource

public void setResource(String resource)
Setter for resource property

Parameters: resource - the new value

setSerialize

public void setSerialize(boolean serialize)
Setter to tell the cache to serialize objects

Parameters: serialize - if the cache model is to serialize objects

Copyright © 2011. All Rights Reserved.