Message Image  

BPM, Workflow, and Case

 View Only

Recipe: Service Caching in IBM BPM / IBM BAW

By Atanu Roy posted Fri September 24, 2021 12:13 PM

  

Skill Level: Beginner

Ingredients

I have used IBM BAW v18.0.0.2 while creating the sample but I think it works for other versions of IBM BPM as well like v8.5.0, v8.5.5, v8.5.7 etc.

Step-by-step

  1. Let's Understand the Caching Feature of IBM BPM Services

    IBM BPM provides a feature of caching service outputs for unique combinations of input values upto a certain number (configurable) of combinations.

    To enable caching in a service we need to navigate to the “Overview” tab of the service and click on the “Enable caching of service results” checkbox. As soon as the checkbox is checked, four boxes with different time units (Days, Hours, Minutes and Seconds) will appear and we can easily configure the required duration of keeping the cache.

    As shown below – 

    1

    Now, let’s see the limitations and other important configurations related to service caching – 

     

    Limitation: 

    The service result cache works only for top-level services that are called directly. If a service is called within another service as a nested service, the cache setting does not apply. We’ll see how can we manage this limitation later in this tutorial.

     

    Configurations:

    • By default, the cache stores up to 4096 results, that means it can cache output results for upto 4096 input parameter combinations.
    • This value is configurable in 100Custom.xml file by setting a different value for <service-result-cache-size>
  2. Let's create a general system service - will cache the results of this service.

    So, I have created a general system service “SampleCacheService” which will take service name as input and provide the service id back as output using the system JS API.

    I have enabled the caching as shown above.

    The I/O mapping is like – 

    2

     

    In the service I have implemented a script block to retrieve the service id like – 

    3

     

    And simply the code is  – 

    5

    I have added this log info to make sure whether the service is called or not.

     

  3. The Trick - Let's try to call the cached service from a human service to visualize the result

    I have created a simple human service with a coach with one input text, output text and one button. The idea is to get the service id after entering the service name and clicking on the button.

    6

     

    The trick: If you see the service diagram, instead of calling the cached service as a nested service, I have added a script block which will be calling the cached service using JavaScript API.

    7

    I have implemented the script block like – 

    8

    So, I have used the JS API to invoke the cached service which means I am bypassing the limitation and calling the service directly.

  4. Final step : Testing the solution

    So, I am done with the cooking, it time to test (taste) the results – 

    If I run the human service, it looks like – 

    9

    Now, If I provide some service name and hit on the button – 

    10

    Wow, I got the service id, and this is what I see in the SysOut logs – 

    [09/03/19 00:13:20:322 IST] 0000020c LoggerScripta I Service Called

     

    If I hit the button again, I see the same result as above but nothig in the SysOut logs which means the service has fetched the result from the cache for the provided input.

     

    Now, Let me provide another service name  and hit the button – 

    11

    I get a different service id in this case and let me see the SysOut logs – 

    [09/03/19 00:13:20:322 IST] 0000020c LoggerScripta I Service Called
    [09/03/19 00:17:07:589 IST] 00000214 LoggerScripta I Service Called

     

    I have got another entry in the SysOut logs for this service call. 

    If I press the button again with the same input, it gives me the result back but without calling the service. 

     

    So, our solution works well !

    I hope this will help developers while developing integration services for fetching kind of static data which change very rarely.

    If you are going through this recipe, kindly share your views. Any suggestion, idea, criticism is welcome.

2 comments
63 views

Permalink

Comments

Fri November 08, 2024 12:57 AM

@RK Chandra Hello, I am not aware of any such functionality to reset the service cache programmatically. If you have such requirement, then you can opt for more flexible and sophisticated cache mechanism like Dyna Cache.

Otherwise, you may reach out to IBM Support to check if there is a way for the option you are looking for.

Fri October 25, 2024 10:25 AM

For my use case, I’m fetching the email service password from the vault, which is rotated every 3 months. I’ve set the cache duration to 12 hours, so it retains the password and only re-fetches it after the cache expires.

However, I’d like to know if there’s a way to dynamically reset the cache in case of any failures due to an incorrect password. This would allow the application to immediately retrieve the latest password from the vault, rather than waiting for the cache to expire. will that be possible here ?