Using OJB with JCS.

This page will explain you in 4 steps how to configure Apache JCS as Object Cache for OJB in Cocoon.

Prerequisites

Facts

Platform

I think it works in any configuration, but just in case, here isthe tested platform:

Steps

Let your servlet breathe calm

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

Tell OJB to use JCS

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

Tell Cocoon that OJB will use JCS

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

That is all!

Now restart Tomcat and start to use JCS. You will notice a performance improvement. Good Luck!

More info:

-- AntonioGallardo

UsingOJBWithJCS (last edited 2009-09-20 23:42:51 by localhost)