Thursday 28 April 2016

Service Result Caching in OSB


Oracle Service Bus 11g provides built-in cache functionality that utilizes Oracle Coherence, support for many caching strategies.

Oracle Coherence Integration:-

Oracle Service Bus always had some mechanics of caching in order to provide XQuery and XML beans caching, in addition to object caching for Proxy and Business Services classes. But from 11g Release 1 onward, Oracle Service Bus offered an integrated solution for result caching with Oracle Coherence.

The result caching in Oracle Service Bus is available for Business Services. When you enable result caching, the Business Service will not reach the backend service and the response will come from the cache entry. This entry can expire and if the entry is expired, the next service call will indeed reach the backend service and update the cache entry.

 
Activating Cache for Business Service
To enable result caching for our Business Service follow these steps: Open any business service

Expand Advanced Settings and in Result Caching select Supported. Set the Cache Token Expression: fn:data($body/ser:getCustomer/arg0)
 


This will use the customer ID as our unique token for the cache entry. Also, set the Expiration Time for 10 minutes.
Click Last >> and Save to confirm the Business Service modifications. You can activate the change session.
Now test the proxy service

Now the result will show the results immediately, directly from a cache entry in the embedded Oracle Coherence Server running within Oracle Service Bus.  The cache Expiration Time (Time-to-Live) is set to 10 mins, so during this period your calls will not hit the backend Web service.

More complex cache tokens :-
Your desired cache token key may not be as straight forward as selecting the contents of a single, predictably placed node.
 It is worth noting that the Cache Token may be specified as any expression you like, using the XQuery functional programming language.
 XQuery has a rich syntax for constructing queries, including the use of many system libraries with common functions such as numeric operations and string manipulation.
Clear the cache explicitly:-
It might be that you can’t risk the cache becoming stale under certain circumstances. If that is the case, rather than using a time parameter to manage the lifetime of the cached responses, mark critical requests with an additional flag and select XQuery Expression in the expiration time options to test for the existence of this flag.

6 comments:

  1. Very useful info. Thanks for sharing.

    Regs
    Rajathraj

    ReplyDelete
  2. Very useful info. Thanks for sharing.

    Regs
    Rajathraj

    ReplyDelete
  3. Please Note: Service result caching works only when the business service is invoked from a proxy service!

    ReplyDelete
  4. Can you give an example for the following statements that are part of your blog:

    Clear the cache explicitly:-
    It might be that you can’t risk the cache becoming stale under certain circumstances. If that is the case, rather than using a time parameter to manage the lifetime of the cached responses, mark critical requests with an additional flag and select XQuery Expression in the expiration time options to test for the existence of this flag.

    ReplyDelete
  5. How to clear cache business service osb 12c ?
    Please give details step by step.

    ReplyDelete
    Replies
    1. I know this question is old but if someone pass by this problem,
      If for some reason you have a problem which you need to force a clean the cache in the 12c, you can go to EM>SOA>Service Bus>Operations and disable the cache apply and enable it again, for other reasons where you need to clean it for a certain key, you might need to build a custom cache, either in JAVA or using coherence adapter. I hope this help someone in the future.

      Delete