Wednesday, June 4, 2014

Service Result Caching is one of the options that you can use when you want to improve Oracle Service Bus performance. Service Result caching is used when we have business service which connects to external service which returns somewhat static response. So by using Service Result Caching we don’t hit external service for same request instead it will take the response from cache which improve the OSB performance.

We can also set the Time to live for cache. Once that time expires business service will again hit the external service for response.


As shown in above diagram, if you have enabled result caching, first time we invoke the business service it get the response from external service but when we hit this service again with same request then it take the response from cache.

In this post, I will show you one use case of service response caching.

For this post, I have created a SOA composite which we use a external service. In the SOA composite, I put a wait activity of 30 seconds. So ideally first time when we invoke business service then it should return the response after 30 seconds only and when we call it next time with same request then it should not take more than 1-5 seconds as it get the response from cache.


First create a SOA composite, add a Synchronous BPEL to it. Simply assign the request to response and put 30 seconds wait activity.



Now create a new project is OSB. Import above created SOA Composite WSDL & Schema file to this OSB project.

Now create a Business service which invokes external service (SOA Composite). Name your business service and choose SOA Composite as service type.



To configure the caching for this business service, click on “Result caching” check box and enable the result caching.

You also need to specify “Cache Token Expression” which will be your request message key value.

Set Expiration Time for caching. Once this time expires , business service again get the data from external service instead of cache.





Now create a proxy service which invokes above created business service.






Testing Result:

Test your proxy service, since this is the first time so business service will invoke the external service and get the response. We have added 30 second wait activity in external service so we should get response after 30 seconds only.


Now test you proxy with same request. Now you should immediately get the response as business service take the response from cache.




2 comments :

  1. Hello mr. Garg,
    I'm looking to alter the Expiration time in a customization file. Would you happen to know how to do this? It doesn't show up in the generated ALSBCustomizationFile.xml

    Regards,
    LH

    ReplyDelete
    Replies
    1. I don't thing expiration times comes in customisation file, you need to manually edit it if needed.

      Delete