Retrieving data from a back-end system or executing something in a business rule engine can cost quite some time. When we build services we want to strife for performance but sometimes you make services which you just can’t make any faster. One thing to keep in mind is that it is possible to cache in SOA Suite using the coherence adapter. For example retrieving data from a back-end system in a composite and enriching it takes 1400ms average but during a 24 hours, you might get 15% call with the same request, which should give exactly the same answer! To do the retrieving and enrichment every time seems like a shame. This is where the Coherence adapter comes in.
The Coherence adapter can store certain pieces of data for a certain amount of time. This overview consists of 2 parts. The first one is the configuration of the coherence adapter in weblogic, the second part is the usage of the coherence adapter in a composite. Now lets get started.
Configuring the Coherence adapter
- The Coherence adapter isn’t active out of the the box. It is not targeted to any managed server so the first thing you have to do is to target it.
Go to your SOA server’s console, go to Deployments and click the CoherenceAdapter. Go the the tab Targets. Look if it is targeted. If it is not….target it. Click Lock & Edit and check soa_cluster checkbox, click Save and Activate Changes:
- The next step is to add cache configuration file. This step requires that you have to physically put an XML on the file system of the server. In our example it is a file called ProductServiceCache-Configuration.xml and sat in location /u01/domains/dev_soa_domain. On a clustered environment the file have to be on both servers! My configuration file looks like:
ProductServiceCache transactional transactional DistributedCache true It is wise to create separate caches for separate services in case you want to set different cache timers or in case of the occasional flush.
- The next step is creating a Coherence Adapter Connection Factory. Go to your SOA environment console, deployments and click on the Coherence Adapter. Go to the tab Outbound Connection Pools. Click New. Choose javax.resource.cci.ConnectionFactory. Input your JNDI name. I will have eis/Coherence/ProductService and click Finish. Now select the connection factory you just created and choose the Properties tab. Set the following values:
-
As a last step, you will have to update the CoherenceAdapter with the settings. You can do this by stopping en starting the CoherenceAdapter. Go to Deployments and click Lock & Edit. Select the checkbox of the CoherenceAdapter and click Update and the Finish.
Oke now we have configured Coherence including a cache for the ProductService.
Making use of the Coherence adapter in a composite
To make use of the adapter in your BPEL, you will have to add 2 JCA connections.
We are going to call them retrieveResult and writeResult. Lets start of with the retrieveResult. Drag the Coherence Adapter onto the right part of the canvas and follow the wizard:
On the step 4 when pressing Finish it will ask you No cache key specified. No worries as we will do this later on.
No we will create a writeResult JCA adapter:
I set the Time To Live of the cache to 10.000 milliseconds for the test.
Now wire your BPEL to your 2 adapters like you would normally do. This would look like this then.
Now in your BPEL you want to do 2 things:
- Check if something is in the cache based on your key, and if it is return the result.
- If it is not in there, do your normal thing and write the result into the cache
The reading and writing can take place like normal call-outs as you can see. Just drag an Invoke action onto your BPEL and wire it the correct Partnerlink. Lets first do the retrieve. Invoke the retrieveResult and create input and output variables like you would normally do. For the unique key, go to the Properties tab and add property jca.coherence.Key. Here you define the unique key for your result. I just concatenated some string from the request.
In your BPEL you can check if the retrieve call gave you some data back. If it did, you can skip all the normal processing and just return the result. If you ended up with nothing, you want to do normal processing and at the end, write the result to the cache. Use the same Property again and make sure you assign the expression or variable which you used to retrieve something.
It is that easy. My composite will look something like this now:
Now just build and deploy and see if it works!
My first soap call takes about 1777 ms….and that is without a cache hit. Now lets call it again within 10 seconds. There we go….800 ms. Now let check the EM to see if we hit the actual cache:
There we go!
Some considerations:
- This is an easy way to make things faster. Do keep checking with Performance, Load and Stress tests what will happen to you CPU and Memory usage on big loads. The A-team have some good articles about this.
- You might want to have the Time-To-Live different per environment. So for example 10 minutes on Dev but 1 hour on Test and 24 houres on Prod. You can easily do this making use of server tokens. Add them in the EM under tokens and use them in the JCA files like ${ProductServiceCacheTime} for example.
References:
- http://www.ateam-oracle.com/using-the-12c-coherence-adapter-to-access-a-non-transactional-local-cache/
- https://docs.oracle.com/middleware/1221/adapters/develop-soa-adapters/GUID-EA82A9A3-656E-464A-B764-E076C172BAEF.htm#TKADP2495
Hi,
Where you able to test TTL with this configuration. I have implemented Coherence Cache in similar way but TTL is not working. I have created custom cache config file like how you have mentioned in this blog. I have tested TTL by setting it to 2 mins or so but the cache entries are not getting expired. Please let me know if there is any additional config required for this to work.
Hi Vyshali,
To be honest, I have seen it work when I was doing the development but later on in the process we saw that it indeed ignored the TTL. I have no clue why it does so and we haven’t had time to investigate since so if you find the solution….please let met know 🙂
Hi hugohendriks ,
Same problem here. I have tested the TTL configuration on Oracle SOA Suite 12.1.3 and 12.2.1 but it doesn’t seems to be working. Even implemented the same composite with provided configuration as specified on Oracle A-Team blog http://www.ateam-oracle.com/using-the-12c-coherence-adapter-to-access-a-non-transactional-local-cache/ but TTL was not working. Further I added 10000 and 1000 to my cache configuration file but still no luck. Below is my custom Cache Configuration file-
—————————————————————————————————————-
local-caching
no-trans-ttl
no-trans-ttl
LocalCache
false
10
10
—————————————————————————————————————-
Hi hugohendriks ,
Same problem here. I have tested the TTL configuration on Oracle SOA Suite 12.1.3 and 12.2.1 but it doesn’t seems to be working. Even implemented the same composite with provided configuration as specified on Oracle A-Team blog http://www.ateam-oracle.com/using-the-12c-coherence-adapter-to-access-a-non-transactional-local-cache/ but TTL was not working. Further I added ‘expiry-delay’ to 1000 and ‘flush-delay’ to 1000 in my custom cache configuration file(inside caching-schemes) but still no luck. Any help please!
Hi Kumar,
To be honest…..we haven’t found a solution for this yet so I can’t help you here right now :/ If you find the answer….please post it here also…I am curious!
As I can figure out the current implementation looks like for Local Caches. Isn’t it? If yes then below is somewhat Oracle Docs says-
Problem- Coherence cluster on a single machine is not picking up the TTL parameter On : 12.1.2.0.0 version, Oracle Coherence.
Time to Live – Choose Default, Always, or Custom. If you choose Custom, you can specify a value in milliseconds. This value indicates how long an entry should remain in the Coherence cache. The default is that the message never expires. The Time To Live property is applicable more for Remote Caches than for Local caches. For a Local cache, the entry always remains in the cache until you remove it or the SOA server terminates.
https://docs.oracle.com/middleware/12211/adapters/develop-soa-adapters/GUID-EA82A9A3-656E-464A-B764-E076C172BAEF.htm#TKADP9414
Do not use TTL when using local coherence cluster but only use and expect to work against the remote cluster caches.
———————————————————
Next, did you tried to implement the same against the remote cluster caches. If yes then can you please share the steps required to do so.
Thanks
Kumar
I haven’t tried the remote cluster caches so I can’t help you there unfortunately.