Summary – In Previous articles we have created a new Custom Budget BOD Service and integrated it with the WCS REST framework . The Fetch Implementation in GET verb is responsible to get the data from DSL .
There may be some scenarios which may come in the way for what we need to do some caching of our accessed data to improve the performance of WCS Application.
One is Dynamic caching ,what we all are aware about .
Another is an enhancement of caching mechanism to cache the query results at the Business Logic Layer (Wherever you are getting the data ).This is called Data Cache
Cache able data in WCS can be cached in either ways :
- Command caching
- Distributed Map cache (IBM’s recommendation is to use this for better performance)
Scenario – Consider a sample Use case “To Display the name and address of all active Manufacturers and their preferred manufacturing category in B2B Store “.
For this scenario, i have created few custom tables , a new Custom BOD Noun (Manufacturer) and created/loaded around 500 sample records to perform some caching . Once the GET service of Manufacturer noun is invoked , the data is accessed from Data Base via DSL and gets cached in separate custom Distributed Map Object.
Note : I have used the multiple step queries and Graph composerin .tpl file for this BOD module to access the Manufacturer data via DSL. For more information , please refer:
How to do that
- Create a new Manufacturer BOD Module .
- Create a new Distributed Map Object instance in WAS Admin Console in Resources > Cache Instances>Object cache instances (See the image below )
- Every cache object is mapped to a JNDI name . So the Object can be looked up by JNDI lookup using InitialContext.
- create a new Cache class , here i have created ManufacturerInformationCache .
- Create a new static inner class in your cache class and implement CacheableDataGenerator, CacheDependencyIdGenerator
- Override generateCacheableData and generateCacheDependencyIds methods in inner class.
- generateCacheableData method is responsible to generate the data which will in cache . you can implement the logic to hit your DSL based on the selection criteria in this method, the returned data will be cached .
- generateCacheDependencyIds generate some dependency ids. (Below is the image of ManufacturerInformationCache class for your reference that how does it look like )
- Modify your implementation to hit the cache object ,which is hitting the Data Access Layer
- Here , the Fetch Implementation is responsible to hit the DSL , i have modified the Fetch command to get the data from ManufacturerInformationCache.(See the image below for reference)
- Hit the GET service from JUnit and see the cache contents in your extended cache monitor . (Make sure you have installed cache monitor and updated theCache Monitor to extended cache monitor ).
- Below is the image of Manufacturer GET Response and its cache contents in cache monitor .
(GET Manufacture Response- That’s a Biggy response having 500 records )
- Manufacturer Cache Contents-
- Create a new entry in wcs.cacheivl.trigger.sql file for the custom tables if you want to invalidate the cache on any update in manufacturer custom tables.
- These database triggers cause specially formulated invalidation IDs to be appended to the CACHEIVL database table, in the DATAID column
- Create a new REST module for Manufacturer Noun and integrate it with Store front .(see the image below, the sample manufacturer names and sample address grouped by their manufacturing category):
- REST response of manufacturer noun :
Please refer the below link on creating a new REST module for a new BOD module :
Conclusion :- We have created new BOD noun Manufacturer , its data cache class which will hold the data accessed by the GET manufacturer service .
Note:- Use Data cache always for better performance for any data which you think can be cached for WCS application. This approach will definitely increase the performance and reduce the system load
For any questions/concerns or any suggestion if you are having , please feel free to reach me on firstname.lastname@example.org