Most of the times in your baseCache instance falls several different types of cache entries: full pages, fragments, marketing command objects, policies.
Based on the “Best practices for caching design and decisions“, those entries could be moved to a different (or differents) servlet cache instances placed “in the default traditional DynaCache provider for the WebSphere Application Server provider or the WebSphere eXtreme Scale DynaCache provider”.
In general depending on the invalidation volume, you can evaluate moving the most frequent invalidated cache entries to a different instance (an high invalidation rate is not good for WXS) and create a replication domain to associate it.
But how to create a new servlet cache instance and use it in Websphere Commerce?
First you have to create a new servlet cache instance through WAS console
and follow the Knowledge center indications about his configuration adding all needed custom properties.
Restarting the server, these message on sysout will tell you the new servlet cache instance is up and running
CacheServiceI I DYNA0015I: Dynamic Servlet Caching encountered an error: Error type=config warning. cacheName=services/cache/AuroraESpots CacheConfig.disableTemplateInvalidation=true. Template invalidations are disabled for JSP reload.
ResourceMgrIm I WSVR0049I: Binding AuroraESpots as services/cache/AuroraESpots
ServerCache I DYNA1001I: WebSphere Dynamic Cache instance named services/cache/AuroraESpots initialized successfully.
Now services/cache/AuroraESpots instance has to be configured on cachespec.xml
On this sample we will move espot JSP snippets from baseCache to the new services/cache/AuroraESpots cache instance.
This is quite simple: all marketing cache entries has to be placed into this tag
I copied marketing cache entries from the sample cachespec.xml file in WCDE_installdir\components\foundation\samples\dynacache\marketing\cachespec.xml
To check this cache configuration we will simply load Aurora home page.
This page view will generate a cache entry for every espot in the page.
This is not the OOB behavior: I added a cache entry for JSP snippet caching based on activity behavior on
and I changed ContentRecommendation.jsp as explained on Knowledge Center.
With this configuration, loading Aurora home page
9 cache entries are created
All those entries are associated to the JSP snippet caching
as you can see opening one of the entries
One thing to specify: the 9 espots are cached with specific cache entries because there is no cache entry for TopCategoriesDisplay in the sample cachespec.xml file I used in this post.
“Optional: Some optional parameters for an e-Marketing Spot can be configured as follows:
If the e-Marketing Spot JSP is included in a servlet cached page, then a static e-Marketing Spot has the JSP consumed by the parent page. If you want to always cache the e-Marketing Spot JSP separately, then define a cacheWithParent parameter with a value of false.”
And now the second part: invalidate the generated cache entries in our custom servlet cache instance.
First of all you need to apply an APAR if Commerce FixPack 7 is not installed (or request a build for your environment)
Then you have to add a special cache entry in your cachespec.xml
<component type=”method” id=”getString”>
This will allow to DynacacheInvalidation job to identify the custom servlet cache instance and send them the correspondent invalidations inserting a specific string (“cmd:”) in TEMPLATE column on CACHEIVL table.
“If the scheduler job locates a value in the TEMPLATE column that starts with cmd: prefix for a new row, the job uses the rest of the value that follows the prefix as a Java class name…”
To understand the whole process we are invalidating the JSP snippet corresponding to the HomeLeft_Content espot (the image with Shirt Sale 15% off men’s dress shirts)
The EMarketingSpotMetaDataGenerator associated to this entry generates 4 dependencyIds: emsId:10752,contentId:10156,contentId:10157 and contentId:10158.
We can invalidate that content using one of them: let’s use the emsId.
To invalidate that content we will use DynacacheInvalidation scheduled job inserting a specific record con CACHEIVL table
INSERT INTO cacheivl (template, dataid, inserttime) values (‘cmd:com.ibm.commerce.dynacache.commands.StringHolderCmdImpl’, ’emsId:10752′, CURRENT TIMESTAMP);
As explained in Knowledge center (it could be explained better ;-)), we have to use the pattern “cmd:”+java class on TEMPLATE column and then indicate on DATAID column the dependencyId to invalidate.
After waiting for DynacacheInvalidation execution, the cache entries on our custom servlet are 8 now