Response cache not working as expected

madhu-2
Participant II

i created the api proxy for internal route and called that api proxy from postman with session and required parameters it shows data but when i add cached response to proxy endpoint preflow and called that apiproxy from postman time is not reducing and in use case it is not hitting response cache policy element

0 9 496
9 REPLIES 9

sidd-harth
Participant V

Provided info is not enough to give an answer.

Add your policy configs, trace sessions.

@Madhu Latha Bandaru

Response Cache policy needs to be attached in the request preflow of proxy endpoint (for lookup) and the response preflow (for populating the cache)

If your response cache policy is attached to the flow with conditions, check if the conditions are satisfied.

If possible post your trace session and the proxy endpoint xml, that gives some additional details to help resolve your issue.

Parallelly you can look at some samples for the response cache usage -

https://github.com/apigee/api-platform-samples/tree/master/sample-proxies/response-cache

https://youtu.be/TUBGNxUCp7w

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ProxyEndpoint name="default"> <Description/> <FaultRules/> <PreFlow name="PreFlow"> <Request> <Step> <Name>Response-Cache-2</Name> </Step> </Request> <Response/> </PreFlow> <PostFlow name="PostFlow"> <Request/> <Response/> </PostFlow> <Flows/> <HTTPProxyConnection> <BasePath>/getbyclukey</BasePath> <Properties/> <VirtualHost>secure</VirtualHost> </HTTPProxyConnection> <RouteRule name="default"> <TargetEndpoint>default</TargetEndpoint> </RouteRule> </ProxyEndpoint>

there is no condition

is this is trace session

@Madhu Latha Bandaru

Yes this is the trace session, however you have provided the screenshot only. Click on the Download trace Session button, you will get a trace*.xml file. Rename that to .txt extension and post it here.

The trace session image shows your response cache policy is executed. However, it could be a cache miss. If you click on the response cache policy, and scroll down in the panel below you will see a variable <policy-name>.cachehit which will be true/false. That determines whether data was found in the cache or not.

sidd-harth
Participant V

Thanks for the trace.

You are using two different session ids in the request so the Cache is missing.

Session ids should bve unique for cache to work.

Actually I changed session that won’t be the issue

Changing the session id is the issue!

In your Response Cache policy, you have added,

<CacheKey>
        <Prefix/>
        <KeyFragment ref="request.queryparam.session" type="string"/>
 </CacheKey>

This means that the Response Cache policy will create a cache for every unique session id which is present in the query parameter.

If you make calls with the same session id, you will get the response from cache and latency will be reduced.