Saturday, April 11, 2015

Server side Caching in IBM BPM with jsCache

Many of us might come across this requirement of server side caching mechanism in IBM BPM, especially when the applications are UI heavy, involves lots of users or expensive data preparations. In these kinds of scenarios Caching comes to rescue in-terms of improving performance by avoiding expensive operations like database calls or web service calls to fetch the commonly used or rather static data (which doesn't change more often) that needs to be displayed on to the UI. In IBM BPM, there is beautiful option for this called jsCache.
How jsCache works? 
jsCache stores data server side as mutli-level javascript Map (Key-value pair), with the first level being the name of the cache and map of the values to be stored corresponding to that cache name. Each data key in a given cache can be associated with an expiry time (optional though), so that the cached data can be refreshed at regular intervals of time. Figure 1 helps illustrate the storage of data in jsCache,

Figure 1: illustration of jsCache
You can download the jsCache.js file  by clicking here.

How to use jsCache in IBM BPM?

Attach this js file as a server file in the files section as show in the Figure 2.

js cache attachment in IBM BPM Files section
Figure 2
Below are the important methods in jsCache.
1. jsCache.setValue() --> used to store values to the jsCache.


Figure 3

2. jsCache.getValue() --> used to get the stored value based on cacheName and datakey.


Figure 4

Figure 5 shows a sample implementation of jsCache in IBM BPM for fetching list of statuses from jsCache.

Figure 5
In Figure 5, step 1 tries to get the list of statuses from jsCache . step 2 checks if the values are available. If yes then the flow will be routed to end else  at Step 3 the nested service "fetch status List" will be executed (either DB call or web service call or some logic to prepare list of statuses) to get the status values List and step 4 loads the values to the jsCache again. Once these values are set to Cache, from the next time when user loads the screen, these status values can be fetched directly from cache untill the cache expires which helps avoid the expensive DB or Web service calls.

you can also find an article / example of jsCache in bpmwiki.

Hope you like this post !!

Thanks for stopping by. If you like this post leave a comment, share it and do a g +1.

1 comment: