This blog promotes knowledge sharing through experience and collaboration. For more product information, visit our WebSphere Commerce CSE page. For easier navigation, utilize the Categories to find posts that match your interest.
Activate baseCache on Search Server for REST calls
One of the most interesting features introduced with feature pack 7 is the capability to deploy and scale the search and browse storefront traffic separately from WebSphere Commerce. Finally WebSphere Commerce architects can apply the CQRS (Command Query Responsibility Segregation) pattern to their solutions.
In particular the new FEP7 Search deployment option provides new caching options for the Search infrastructure
How to activate dynacache on Search Server?
Andres introduced in a previous post how to enable data cache on Search server: in this post we'll focus on activate caching on baseCache for Search REST requests.
After enabling dynacache service at JVM level, we have to configure it to cache Search REST requests adding a cachespec.xml file on the application module used on Search EAR to return REST responses: the Search-Rest module
To cache JSON or XML REST responses on Search server you can start using the sample template available on WCDE_installdir\components\foundation\samples\dynacache\Search-Rest\cachespec,xml in a Commerce developer workstation or creating a new one from scratch following the suggested caching strategies.
It's mandatory to apply a specific APAR (JR52222 CREATE SAMPLE CACHESPEC.XML FOR SEARCH SERVER FOR FEP7 AND FEP8) to have that template available on your Commerce developer installation: contact IBM support to ask it.
Generating cache contents on both servers
Once you've setup up and configured dynacache on Search servers, you can start navigating Aurora FEP7 store and seeing cache entries showed up both on Commerce server cache monitor and and Search server cache monitor
Wtih dynacache service activated on both JVMs, Commerce and Search, and using a specific cachespec.xml file on both, on Stores.war module and on Search-Rest.war module, browsing the Aurora FEP7 website a lot of cache entries are generated as we can see on the two cache monitors
And now? How to invalidate?
When you define a cache strategy, you always have to establish how to invalidate what you decided to cache.
In general we already know how to invalidate cache contents on Commerce servers, but how does it work on Search server?
The same way invalidations are working for search data cache: configuring Search_demo.ear/xml/config/com.ibm.commerce.foundation/wc-component.xml under this node: <_config:configgrouping name="CrossTransactionCache">.
As specified by Andres, no Commerce Scheduler is running in the Search servers so invalidations are implemented differently. Instead of using the DynacacheInvalidation job, the Search runtime periodically checks for pending invalidations before executing each request. This behavior is not documented on Commerce Knowledge Center and you have to use the comments inside wc-component.xml file as a guide.
Invalidate a cached Search REST response
For example, if you want to invalidate a specific REST response (a JSON with category information in this case)
we can use its dependencyId ("CategoryDisplay:storeId:categoryId:10152:10006") to do it.
When a REST request is cached, RESTMetaDataGenerator programmatically associates a specific dependencyId to the cache entry to allow a successful invalidation.
The pattern used on REST category responses is "CategoryDisplay:storeId:categoryId"
To invalidate that entry we'll use the Dynacache API and CACHEIVL table invalidation method.
Insert a record on CACHEIVL table where DATAID column value is equal to the dependencyId of the cache entry we want to invalidate. Then wait for DynacacheInvalidation task execution.
The insert statement is quite simple: we have to specify "CategoryDisplay:storeId:categoryId:10152:10006" as DATAID and the current timestamp on INSERTTIME table
But how much should be wait?
As you can see the record was inserted at 21:16:28.
The time interval between DynacacheInvalidation execution is specified in Search_demo.ear/xml/config/com.ibm.commerce.foundation/wc-component.xml using this property
<_config:property name="CrossTransactionCache/invalidationJobInterval" value="60"/>
Then every 60 seconds CACHEIVL table would be checked to see if there are new entries to invalidate
And if you keep navigating the store generating new REST search requests, one minute later
[9/16/14 21:17:26:233 CEST] 0000008e DCInvalidatio > com.ibm.commerce.dynacache.commands.DCInvalidationCmdImpl performExecute ENTRY
On this post we find out how to activate and invalidate Search REST responses using baseCache on Search server in a Commerce FEP7 installation.
Special thanks to Robert Dunn and Patrick Yau for checking all caching implications and revise post contents.