Showcase the caching capabilities of Synapse by implementing a simple response cache in Synapse for an actual service deployed on Axis2
In this sample, the message sent to Synapse is checked for an existing cached response by calculating the hash value of the request. If there is a cache hit in Synapse, then this request will not be forwarded to the actual service. Rather, Synapse responds to the client with the cached response. In case of a cache miss that particular message will be forwarded to the actual service and caches that response in the out path for the use of consecutive requests of the same type.
To try out this scenario, send a request from the sample client as follows.
You will notice that if you send more than one requests within 20 seconds, only the first request is forwarded to the actual service, and the rest of the requests will be served by the cache inside Synapse. You could observe this by looking at the logs printed by the Axis2 server, as well as by observing a constant quote value in the response to the client instead of the random rate, which changes by each and every 20 seconds.