Caching in OSB 12c
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.
Request-1
Response-1
See the firsname and lastname
Let’s change the firstName and lastName values in the DB so quickly
Hit the request before cache expires
Request-2
Response-2
See the response has been served from cache it self.
Let hit the request after 2 minutes and see the response
Request-3
Response-3
Now you can see the updated result. That time data has been fetched from database.
That’s it !!
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:
$body/dbr:DBReferenceSelect_deptIdInputParameters/dbr:deptId@someAttribute/text().
Many regards.
Mauricio.
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:
elementName/@atrributeName
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?.
Regards.
Mauricio
Hi Ankur,
Can we have multiple parameters as combination. For example can we have both A & B as input parameters for Cache.
Regards,
Ganesh.
What if i enter dept id as 20. Will it fetch from db or cache.what is the use of key in above use case.tia
Thankyou for sharingerp software companies