Cache handling in proxies which return both XML and JSON response

1 1 413

Suppose you get a scenario where you have to design a proxy which gives a JSON response or XML response based on the 'Accept' Header. If the user of the proxy sends, Accept header = application.json, you should gives JSON response, if he sends application/xml, you should guve XML response. If you have added a response cache in such a proxy, you will run into some issues

1.) If the user expects a JSON response, a JSON output would be stored in the cache.

2.) Now when the user expects an XML response, because the response cache is present in both the request and response flow, it will first hit the response cache and you will get a JSON response instead of an XML response.

The solution to this, is to use a small but a valuable property while configuring response cache. <UseAcceptHeader>true</UseAcceptHeader>

In this case, the accept header would be suffixed to your cache key, which will help the cache distinguish between different types of responses.

Comments
sydub7
New Member

Thanks @Raunak Narooka Great Info !!

Version history
Last update:
‎10-30-2017 11:05 AM
Updated by: