Implement caching control on the newsapi
Closed this issue · 0 comments
By default News API will cache the results of your queries so that if identical requests come in shortly after, for example from multiple clients, they won't drain your monthly query allowance. A cached result will last for 5 minutes.
You can identify if a result has been cached by checking the X-Cached-Result
header on the API response. If the X-Cached-Result
header is marked as true then the result is a cached response. The X-Cache-Expires
and X-Cache-Remaining
headers will also be populated to tell you when the result will expire. The Date header shows you when the request was originally made, so you can use this to calculate current age.
You can disable this functionality on a request level so that the request doesn't return a cached result, nor will it be cached itself. This way it the request will return the freshest data. To do this simply send the X-No-Cache = true
HTTP header with your request. You will be able to verify that a response hasn't been cached by checking for the X-Cached-Result = false
header on the response.
Open for discussion for how to implement this without breaking backward compatibility!