Scenario: Instead of hitting your backend server multiple times, you want to cache the response for the data which is not updated frequently.
Steps:
1. Add an instance of Response Cache in Preflow for incoming request.
2. Modify the code as per requirement.
<CacheKey> is a unique pointer to the data cached. In this case, key is supposed to come in query parameter.
<ExpirySettings> for cached data is set to 3600 seconds
<SkipCacheLookup> specifies when to skip the cache lookup and fetch the response from
backend system.
Code:
<ResponseCache async="false" continueOnError="false" enabled="true" xmlns="http://www.sap.com/apimgmt">
<CacheKey>
<KeyFragment ref="request.queryparam.q"></KeyFragment>
</CacheKey>
<ExpirySettings>
<TimeoutInSec ref="">3600</TimeoutInSec>
</ExpirySettings>
<SkipCacheLookup>request.header.InvalidateCache = "true"</SkipCacheLookup>
<SkipCachePopulation></SkipCachePopulation>
</ResponseCache>
3. Add the same policy for Outgoing Response.
4. Test the API.
In this case, during the 1st call, it will save the response in Cache. During the 2nd call, the response time will be significantly reduced.
No comments:
Post a Comment