Tuesday, 1 October 2013

IBM WCS Dynacache and getting the Extended Cache Monitor installed



As a top tier Enterprise Application catering to the eCommerce Market , One of the Addon Features that Websphere Commerce provides the DynaCache. Although IBM has other products aimed is specifically addressing Caching, since the DynaCache is integrated with WAS server it is a cost effective limited solution.
IBM Websphere eXtreme Scale is a powerful elastic cache solution for advanced cache solutions.

Caching is generally asscociated with static content such as graphics, images , files that rarely change. However, in this age of personalized experiences , websites serve personalized information or data depending on the end user and this changes frequently.

WAS  provides a built in service for caching , using which WCS provides caching of dynamic content using defined caching techniques.
Cachespec.xml is provided for the user to specify and control Caching and invalidation of Views ( Commands or JSP views ).
DynaCache as the name suggests is provided for caching Dynamic Content.


The Dynamic caching service includes :

- Servlet and JSP result cache
     Whole Pages or fragments of a page are cached.
- Command cache
      Commands that implement the CacheableCommand ( cache command objects )
- Edge Side Include (ESI) caching
     To assemble fragments and deliver complete dynamic web pages.
- Cache Invalidation
     Invalidation rules to flush out a cached resource when it may no longer be required based on
1. rule based
2 . time based
3. group based
4. programmatic.


 - Cache Replication  
    To enable cache sharing and replication across multiple servers.

- Disk offload capability
    The cache eats up a lot of valuable runtime memory space. Also the cache slots available is limited and Cached requests are flushed out to make space for new ones once the cache gets filled.
Also since the Cache is maintained in the runtime memory of the server on server restarts this gets lost. This might manifest as an issue on a live production server. 

Now If the Disk Offload is enabled ,
     Once the space allocated for the cache gets filled, The entries that are flushed/invalidated are moved to the Hard disk. The server would maintain an index of the Cache IDs in the disk cache. Thus a much higher number of cache entries can be maintained in the Application server .
Also , on server restarts since the offloaded cache is still available , the cache content is preserved.

    To enable caching large amounts of data, and to preserve cache content while the application server is stopped and restarted. 

Note: After the application server is restarted and the database is restored, it is recommended that you clear the disk cache using the cache monitor. Clear the disk cache to ensure that information that is invalid for the new database is removed. Use the cache monitor  http://host_name:Port/cachemonitor to clear the cache or, alternatively, use the following URL: http://host_name/path/DynaCacheInvalidation?clear=true.


Limitations of dynamic caching

If you use the cachespec.xml file to enable invalidation you might encounter the following behavior:
  • When you create a catalog entry or move a catalog entry from one category to another in the Management Center, the catalog entry would not show up on the storefront.
  • When you create a category in the Management Center, the category would not show up on the storefront.
  • When you update a child object in the Management Center, the parent object cache entry is not automatically invalidated. For example, when you update a catalog entry in the Management Center, the category display page does not reflect the updates in the storefront.
  • Similar anomalies might be encountered while using bod service commands to update changes in a different Backend Application , while the caching is done based on Commands and Views and there is no relevant invalidation configured based on bod service commands invoked. 

 Enabling Sevlet caching

 In order to enable servlet caching do the following. 
 Navigate to http://localhost:9060/admin  ( WAS admin console ) and to the Application server

Click on the Web container
 Select the check box. and click ok. Ensure to save changes to the Master Configuration.

 Installing the Cache Monitor 

The cache Monitor will enable you to view the Cache Content , cache ID , Dependency ID and cache statistics ( Cache Hit / Cache Misses ) etc. It can also be used to clean the cache or selectively invalidate a specific cache entry ( never advised ) .
The Cache Monitor can be installed as a new application on the WAS server. The CacheMonitor.ear can be found on a developer machine 
@ Location  ..\..\IBM\SDP\runtimes\base_v7\installableApps\

Navigate to http://localhost:9060/admin  ( WAS admin console )
Click on Install . 

Browse to the above mentioned file CacheMonitor.ear in the local file system. 

Click Next at the next three screens .
 Step1 , Step 2 Step 3 
Make sure to select CacheMonitor.ear  @ Step 2. 


The IBM Extended Cache Monitor for IBM WebSphere Application Server provides you with two functions that are not available with the cache monitor that is supplied with WebSphere Application Server. These two functions enable you to:
  • display the contents of object cache instances
  • display the Dynamic Cache mbean statistics for cache instances
 
 
The Extended cache Monitor can be installed as mentioned @
http://www.ibm.com/developerworks/websphere/downloads/cache_monitor.html

Incase you run into errors make sure of the following.
Note: The CacheMonitor.ear should be directly under the cachemonitor7_update.zip
 

Category Pages for Mobile Devices - ( default Devicefmt_id taking precedence over the configured devicefmt_id. )

If you landed up here, You were most probably looking for how you could have a totally different set of catalog asset , for one of the various smart devices .

You will have to define the new catalog Asset in the DISPCGPREL table. This table holds the page names used to display CatalogGroups . The selection of page name is based on Store , MemberGroup , DeviceType  , CatalogGroup & Language . 
Catgroup_id = 0  implies that the page is for all catalogs . 
storeent_id = 0 implies that the page for the catalogGroup is for all stores published . 
Mbrgrp_id = 0 implies that the page is for anybody accessing the site. 

DEvicefmt_id = -1 defines that the device accessing the page is a web browser.

Entirely different pages can be displayed for CatalogGroups based on the language as is evident.
Problem :
You have defined a new configuration in the DISPCGPREL table for a non-default device format, that is, a value not -1, however the new configuration is not used. Instead, a category-specific page for the default device format is instead used
You want to configure a unique  Categories display page for a mobile device.  or 

You want to configure a unique subCategories display page for a mobile device.

Resolving the problem


For example, if you have defined the following entries in the DISPCGPREL table:
  1. CATGROUP_ID = 10001, DEVICEFMT_ID = -1, RANK = 2, PAGENAME = /Store/Page1.jsp,
  2. CATGROUP_ID = 0, DEVICEFMT_ID = -2, RANK = 2, PAGENAME = /Store/Page2.jsp
Zero is the fallback value for the catalog group and -1 is the default device format.
WebSphere Commerce implements the following query to retrieve the page based on these parameters:

  • Store
  • MemberGroup
  • DeviceType
  • CatalogGroup
  • Language

SELECT T1.DEVICEFMT_ID, T1.MBRGRP_ID, T1.DESCRIPTION, T1.PAGENAME, T1.OID, T1.FIELD1, T1.RANK, T1.STOREENT_ID, T1.FIELD2, T1.DISPCGPREL_ID, T1.CATGROUP_ID, T1.LANGUAGE_ID, T1.OPTCOUNTER
FROM DISPCGPREL T1
WHERE (T1.STOREENT_ID IN(?,?) or T1.STOREENT_ID=0)
and (T1.catgroup_id=? or T1.catgroup_id=0)
and (T1.devicefmt_id=? or T1.devicefmt_id=-1)
and (T1.MBRGRP_ID=? or T1.MBRGRP_ID=0)
and (T1.LANGUAGE_ID=? or T1.LANGUAGE_ID is null)
order by T1.mbrgrp_id desc, T1.CATGROUP_id desc, T1.STOREENT_ID desc, T1.RANK asc


If a request is made using the following parameters: CATGROUP_ID = 10001 and DEVICEFMT_ID= -2,
given that the catalog group has precedence, /Store/Page1.jsp is returned. This page corresponds
to the row with DEVICEFMT_ID = -1, not -2.


To force the page with devicefmt -2 to be returned, you must insert a new row in the table
for the specific catalog group with a rank that is lower than the rank used for the default device format (-1).
For example:

  1. CATGROUP_ID = 10001, DEVICEFMT_ID = -1, RANK = 2, PAGENAME = /Store/Page1.jsp .
  2. CATGROUP_ID = 0, DEVICEFMT_ID = -2, RANK = 2, PAGENAME = /Store/Page2.jsp .
  3. CATGROUP_ID = 10001, DEVICEFMT_ID = -2, RANK = 1, PAGENAME = /Store/Page2.jsp .

If you query again using CATGROUP_ID = 10001 and DEVICEFMT_ID= -2, row 3 is returned, which is specific for device format -2 .

IBM Websphere Commerce



IBM Websphere Commerce is an e-Commerce Product marketed by IBM. It is a designed to be an unified platform that will cater marketing , sales ,customer , order capturing, order processing , inventory , payment processing needs , as a single package. The platform is built to be open ended , extensible in nature.

It offers the ability to do e-Commerce - directly with the consumers (B2C)  , with other businesses ( B2B ) ( wholesalers , retailers , organizations , governments ) or indirectly through channel partners.

Channels are classified by the number of intermediaries between producer and consumer . ( The retailer becomes one of the indirect intermediaries in the channel ).

Websphere Commerce ( WCS ) uses open standards such as XML and web services conforming to  OAGIS Specifications ( implemented as part of version 7.0 ) which makes is easy to integrate.
Third party applictions providing certain features ,either due functional superiority or legacy requirements or business needs , can be integrated with websphere Commerce.