Jumat, 20 Januari 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.

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 !!

Tidak ada komentar:

Posting Komentar