Package com.ibatis.sqlmap.engine.cache
Class CacheModel
java.lang.Object
com.ibatis.sqlmap.engine.cache.CacheModel
- All Implemented Interfaces:
ExecuteListener
Wrapper for Caches.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Object
This is used to represent null objects that are returned from the cache so that they can be cached, too. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addFlushTriggerStatement
(String statementName) Adds a flushTriggerStatment.void
configure
(Properties props) Configures the cache.void
flush()
Clears the cache.long
Getter for flushInterval property.long
Getter for flushInterval property.Gets an Iterator containing all flushTriggerStatment objects for this cache.double
Returns statistical information about the cache.getId()
Getter for the cache model's id.protected int
Get the maximum size of an object in the log output.Get an object out of the cache.Getter for resource property.boolean
Getter for read-only property.boolean
Getter to tell if the cache serializes.protected void
Log a cache action.void
onExecuteStatement
(MappedStatement statement) ExecuteListener event.void
Add an object to the cache.void
setCacheController
(CacheController controller) Sets up the controller for the cache model.void
setControllerProperties
(Properties cacheProps) Sets the controller properties.void
setFlushInterval
(long flushInterval) Setter for flushInterval property.void
Setter for the cache model's id.void
setReadOnly
(boolean readOnly) Setter for read-only property.void
setResource
(String resource) Setter for resource property.void
setSerialize
(boolean serialize) Setter to tell the cache to serialize objects.
-
Field Details
-
NULL_OBJECT
This is used to represent null objects that are returned from the cache so that they can be cached, too.
-
-
Constructor Details
-
CacheModel
public CacheModel()Default constructor.
-
-
Method Details
-
getId
Getter for the cache model's id.- Returns:
- the id
-
setId
Setter for the cache model's id.- Parameters:
id
- - the new id
-
isReadOnly
public boolean isReadOnly()Getter for read-only property.- Returns:
- true if a read-only model
-
setReadOnly
public void setReadOnly(boolean readOnly) Setter for read-only property.- Parameters:
readOnly
- - the new setting
-
isSerialize
public boolean isSerialize()Getter to tell if the cache serializes.- Returns:
- true if the cache model serializes objects
-
setSerialize
public void setSerialize(boolean serialize) Setter to tell the cache to serialize objects.- Parameters:
serialize
- - if the cache model is to serialize objects
-
getResource
Getter for resource property.- Returns:
- the value of the resource property
-
setResource
Setter for resource property.- Parameters:
resource
- - the new value
-
setCacheController
public void setCacheController(CacheController controller) throws ClassNotFoundException, InstantiationException, IllegalAccessException Sets up the controller for the cache model.- Parameters:
controller
- the new cache controller- Throws:
ClassNotFoundException
- - if the class cannot be foundInstantiationException
- - if the class cannot be instantiatedIllegalAccessException
- - if the classes constructor is not accessible
-
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)
-
setFlushInterval
public void setFlushInterval(long flushInterval) Setter for flushInterval property.- Parameters:
flushInterval
- The new flushInterval (in milliseconds)
-
addFlushTriggerStatement
Adds a flushTriggerStatment. When a flushTriggerStatment is executed, the cache is flushed (cleared).- Parameters:
statementName
- The statement to add.
-
getFlushTriggerStatementNames
Gets an Iterator containing all flushTriggerStatment objects for this cache.- Returns:
- The Iterator
-
onExecuteStatement
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)- Specified by:
onExecuteStatement
in interfaceExecuteListener
- Parameters:
statement
- The statement to execute
-
getHitRatio
public double getHitRatio()Returns statistical information about the cache.- Returns:
- the number of cache hits divided by the total requests
-
configure
Configures the cache.- Parameters:
props
- the props
-
flush
public void flush()Clears the cache. -
getObject
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)
-
putObject
Add an object to the cache.- Parameters:
key
- The key of the object to be cachedvalue
- The object to be cached
-
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
-
log
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 outputaddValue
- Add the value being cached to the logcacheValue
- The value being logged
-
setControllerProperties
Sets the controller properties.- Parameters:
cacheProps
- the new controller properties
-