This page will explain you in 4 steps how to configure Apache JCS as Object Cache for OJB in Cocoon.
I think it works in any configuration, but just in case, here isthe tested platform:
My first attempt to setup this configuration failed because of a OutOfMemoryError
. The problem showed to be that the servlet does not had enough memory to run. ie: add this lines in catalina.sh
:
# Set Java Options JAVA_OPTS='-Xms32m -Xmx128m' if [ -r "$JAVA_OPTS"/bin/setenv.sh ]; then . "$JAVA_OPTS"/bin/setenv.sh fi |
In your OJB.properties
file, find the Object Cache section. Comment the line where is ObjectCacheDefaultImpl
and uncomment the line where is ObjectCacheJCSPerClassImpl
. ie:
#------------------------------------------------------------------- # Object cache #------------------------------------------------------------------- ... #ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCacheDefaultImpl ... ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCacheJCSPerClassImpl |
Cocoon is shipped with a default JCS configuration. Cocoon allow to define new cache regions for JCS via cocoon.xconf
. We need to configure the default region used by the JCS ObjectCache implementation for OJB. Search <store> and add this parameters:
<store logger="core.store"> <parameter name="maxobjects" value="10000"/> <parameter name="use-cache-directory" value="true"/> <parameter name="jcs.region.ojbDefault" value="DC"/> <parameter name="jcs.region.ojbDefault.cacheattributes" value="org.apache.jcs.engine.CompositeCacheAttributes"/> <parameter name="jcs.region.ojbDefault.cacheattributes.MaxObjects" value="1000"/> <parameter name="jcs.region.ojbDefault.cacheattributes.MemoryCacheName" value="org.apache.jcs.engine.memory.lru.LRUMemoryCache"/> </store> |
The last 4 parameters (starting with jcs.region.ojbDefault) define the cache region that OJB will use. You can tell JCS how many OJB Object will be able to cache by changing the value of the parameter jcs.region.ojbDefault.cacheattributes.MaxObjects
Now restart Tomcat and start to use JCS. You will notice a performance improvement. Good Luck!