Hi,
We have implemented java callout which connects to database and forms JSON response.
want to implement cache policy to cache json response from javacallout and send as response in the subsequent request.
We have tried response cache policy but again all the request are hitting bacekend and gives response.
Answer by Dino
·
Mar 14, 2018 at 03:22 PM
I understand that
You cannot use ResponseCache for this purpose.
I advise that you rely on the LookupCache and PopulateCache policies, as well as the AssignMessage policy. The flow logic will look something like this:
<Step> <Name>Cache-LookupJsonBlob</Name> </Step> <Step> <Condition>cached_result = null</Condition> <Name>Java-DatabaseLookup</Name> </Step> <Step> <Condition>cached_result = null</Condition> <Name>Cache-PopulateJsonBlob</Name> </Step> <Step> <Condition>cached_result = null</Condition> <Name>Cache-LookupJsonBlob</Name> </Step> <Step> <Condition>cached_result = null</Condition> <Name>RaiseFault-CacheFailure</Name> </Step> <Step> <Name>AssignMessage-Response</Name> </Step>
Does this make sense?
The Cache lookup and Java db read can both be parameterized, of course. The output of the Java callout would be to ... set a context variable.
The Cache-populate step takes THAT context variable and places it into cache with the appropriate key.
The AssignMessage policy takes the output of the Cache lookup policy (a different context variable) and places it into the response message.
Thanks for the immediate reply.
Do we have to add in preflow or postflow