Friday, 20 January 2017

Caching in OSB 12c

OSB allows us to cache Business Service Response for a given request.

OSB uses the Coherence to support caching. Caching increases the application performance if we configure it in the correct way.

When cache is enabled and any request come to the Business Service then it will first check the cache and returns the result from cache to the consumer else it will call the target service and get the output, return to the consumer and save the output in the cache itself.

This Result Caching mechanism the OSB uses is Oracle Coherence which is included in the Oracle Weblogic server.

Let's see the example how we can enable caching for the Business Service.

Considering we have a Service bus project having one REST service that invokes the database using Business Service. If you don't have a project you can follow the blog. I'm gonna to extend this blog only.

1) Open the Business Service, Move to the Performance tab

2) Check the Enable Result Caching checkbox and select the expression as $body/dbr:DBReferenceSelect_deptIdInputParameters/dbr:deptId corresponding to the Cache Token Expression. That will be the unique token in the cache for each department id we pass in the request.

3) Now, select the Duration radio button from the Expiration Time section and configure 2 minutes. That's means cache will be refreshed every two minutes.

The first request would be served from the database and respective request would be served from cache till the cache expires(in 2 minutes). After that Business Service will hit the database again and refreshes the cache with the updated result.

Let's run the example and see how it works.



See the firsname and lastname

Let's change the firstName and lastName values in the DB so quickly

Hit the request before cache expires



See the response has been served from cache it self.

Let hit the request after 2 minutes and see the response



Now you can see the updated result. That time data has been fetched from database.

That's it !!


  1. Hi Ankur! first at all, thank you for the articule, It was very usefull for me. I have only a question about of Token Expression and it is If it could be a reference to attribute instead of element, for example:

    Many regards.


    1. Dear Mauri,

      First of all Thank you so much for appreciating.

      If you want to get any attribute value of any element, you can use the below expression:


    2. Thank you for you reply, but my question was about the token expression for result caching, if does it accept an attributeName reference instead an element?.