Activate Websphere Commerce Data Cache

Caching contents on WC is not only a cachespec.xml configuration task.

Another powerful feature is to cache database query results using Websphere Commerce data cache.

There are two ways to cache database query results: using cachespec.xml or configuring specified DistributedMap instances.

Probably you already know how to cache those contents caching the related commands.

For example if you want to cache the catalog entry data you need to add to your cachespec this cache entry

<cache-entry>
        <class>command</class>
        <sharing-policy>not-shared</sharing-policy>
        <name>com.ibm.commerce.catalog.objsrc.CatalogEntryCache</name>
        <property name="persist-to-disk">false</property>
        <cache-id>
            <component type="method" id="getFinderName">
                <required>true</required>
            </component>
            <component type="method" id="getFinderArgs">
            </component>
            <component type="method" id="getContextInfo">
                <required>false</required>
            </component>
            <priority>4</priority>
            <timeout>172800</timeout>
            <inactivity>900</inactivity>
        </cache-id>
    </cache-entry>

simply copying it from the samples files on WCD (<WCDFolder>\samples\dynacache\cachespec.xml).

But you can also use “specified DistributedMap instances”. I put it between quotes because is not so documented on infocenter.

First of all what are the “specified DistributedMap instances”?

The default list is here but how should I activate these instances?

This is the tricky part: you have to create an object cache instance using WAS console (on WC 7) or adding a cacheinstances.properties file to your Stores.war\WEB-INF\classes folder (on WC 6).

In theory this process is documented on Commerce infocenter but something on the WAS configuration part is missing.

Suppose you want to cache the catalog entry query results using DistributedMap and not with command caching.

What you have to do first is to find the default DistributedMap we are referring to.

Using the same example above, we find the DistributedMap associated to the com.ibm.commerce.catalog.objsrc.CatalogEntryCache command is “WCCatalogEntryDistributedMapCache”.

Then we create it in WAS console

create new Object Cache Instance on WAS

This is enough to WC to start using it to cache database query results.

If we ask Madisons home page and we open the Cache monitor, we already see the com.ibm.commerce.catalog.objsrc.CatalogEntryCache entries in the corresponding DistributedMap instance

using Object Cache Instance On Cache Monitor

Now you can configure the object instance behaviour in Commerce adding a tag to the Commerce instance file.

The tag is the “CrossTransactionCache” and, in our example, you can add this

     <CrossTransactionCache
		enabled="true"
		commandCaching="default"
		maxInactivityTime="86400"
		maxTimeToLive="172800"
		defaultResultSizeThreshold="8"
		clearUserOnLogoff="true"
		clearUserDataCacheOnLogoff="false"
		maxInvalidationIdsPerTransaction="100000"
		clearCacheOnMaxInvalidationIdsPerTransaction="false"
		reduceMemory="false"
		reduceInvalidationIds="false">
		<WCCatalogEntryDistributedMapCache enabled="true" reduceMemory="false" maxTimeToLive="172800" maxInactivityTime="86400"/>
	</CrossTransactionCache>

to refine the configuration.

Don’t forget the most important part: the invalidation.

As you saw in the cache monitor screenshot, every entry has a default TTL of 172800 seconds.

The best way (and the default) to invalidate these entries is to use the database triggers.

You can find the default database triggers on WCD samples folder (<WCDFolder>\schema\db2\wcs.cacheivl.trigger.sql).

In our example the trigger we have to apply is

CREATE TRIGGER civu_c21_modified
 AFTER UPDATE ON CATENTRY
 REFERENCING NEW AS trow
 FOR EACH ROW MODE DB2SQL
  INSERT INTO cacheivl (dataid) VALUES('WCT+CATENTRY+CATENTRY_ID:%:'
  || RTRIM(CHAR(trow.CATENTRY_ID))
  )
;

to create an invalidation row in CACHEIVL every time there is a modification on a specific record in the CATENTRY table.

I slightly modified the original “civu_c21” trigger to match one of the invalidation ids associated to our entries

WCT+CATENTRY+CATENTRY_ID:%:10185
WCT+CATENTRY+?
WCT+CATENTRY+CATENTRY_ID:?
WCT+?

The default scheduled DynacacheInvalidationCmd will do the invalidation work for us.

Advertisements

Websphere Commerce and Portal Architect ✔ Motivated IT professional with more than ten years of experience, combining Java and JEE developer skills with systems and IBM products installation knowledge. ✔ Strong experience and skills on planning, architecting and implementing complex commerce and portal solutions based on IBM middleware products. ✔ Reliable with a strong network attitude, experience on leading developer's teams and manage international relationships. Specialties ✔ Pleasant manner, reliable. ✔ Ability to consider issues from different point of views. ✔ End-oriented work capacity and problem-solving attitude. ✔ Ability to work with deadlines and under pressure. ✔ Ability to prioritise tasks and manage people. ✔ Ability to increase the whole team skills. ✔ Ability to generate commercial leads

Tagged with: , , ,
Posted in cache, websphere commerce
4 comments on “Activate Websphere Commerce Data Cache
  1. Pradeep says:

    Hi Marco,
    Thanks for your blog. This is one of the blog that helped me in understanding dynamic caching using distributedMap.

    I have done following:
    Included WCCatalogEntryDistributedMapCache,WCUserDistributedMapCache in object cache instance. with the JNDI you provided.

    Restarted server also wc-server.xml have default values. I set all the setting metioned above except invalidation .

    Now i played around the store to see if there are any entries in CACHEIVL table. there are no new entries. I do not see any errors in the logs.

    Please help me out in understanding more
    Thanks,
    Pradeep

    • Marco Fabbri says:

      Hi Pradeep,
      would you send me a more detailed description and the files you modified?
      Regards

  2. umakanth says:

    hi Marco,

    thanks for your blog this blog helped me understand the webpshere distributed data cache.
    can this be used to configure for extended/custom DB tables to cache the accessbean?

    REgards,
    Umakanth

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: