I am using Response cache for caching on proxy end, one on preflow and other on postflow. After the Response Cache on postflow, I have Json2xml and xml2json polices which run on different conditions.
I should ensure the correct format(xml/json based on headers) when returning responses from cache as well. But as of now that is not happening.
Ex. all the below three request have same uri parameter...
Any idea what my Response cache should be ? @Anil Sagar
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ResponseCache async="false" continueOnError="false" enabled="true" name="Response-Cache"> <DisplayName>Response-Cache</DisplayName> <CacheResource>ProductsCache</CacheResource> <Properties/> <CacheKey> <Prefix/> <KeyFragment ref="request.uri" type="string"/> <KeyFragment ref="request.header.Content-Type" type="string"/> <KeyFragment ref="request.header.Accept" type="string"/> </CacheKey> <Scope>Exclusive</Scope> <SkipCacheLookup>(request.verb != "GET")</SkipCacheLookup> <SkipCachePopulation>(response.status.code >= 400)</SkipCachePopulation> </ResponseCache>
Hi,
It is depened on your APi proxy implmentation .
I prefer Not to add the Content-Type and Header accept on your cache Key Because the query parameter Might be different for different header and content -Type.SO we should not cache those.
Only preferece is Request URI.
@Binaya Kumar lenka @Anil SagarOnly using Request URI. doesnt help in returning the correct format(xml/json based on he
aders) when returning responses from cache.
Any tips/ideas and quick response is appreciated 🙂
There is a setting on the ResponseCache policy that provides the behaviour you require. There's no need to explicitly make the headers part of the key.
A quick review of the apigee docs at the link below should help
@Neil Munro, Thanks for answering.
BTW I have actually used below tags, it still did not work. I am confused as of now.
My request headers are Accept and Content-Type
<UseResponseCacheHeaders>true</UseResponseCacheHeaders> <UseAcceptHeader>true</UseAcceptHeader>
<UseAcceptHeader>true</UseAcceptHeader>
should give you what you need.
At the risk of stating the obvious, don't forget to clear the cache before testing when you add this. I'm also assuming every request that you expect to use the cache has an Accept header.
Yes I am clearing the cache before testing and have only used UseAcceptHeader.
1st request has request header - Accept | application/json |
---|
2nd request has request header - Accept | application/xml |
---|
1st request doesn't hit Cache.
But 2nd request is hitting the cache and give JSON response.
It's difficult to know what is happening without a trace file.
Possibilities are that you may be overwriting the headers or you are transforming the xml into json after the response has been retrieved from the cache, but it could be something else.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |