Reputation: 35
I am using a script that fetch users infos from an api. This is how it works I get the id of the user posted in php. Then make a curl request to the api with the user id to get his infos. The problem is that whenever the user refresh the page my script do the work again and fetch the infos to display them. But this api take much time to respond and it makes my script works slower. Is there any solution to cache the api response for sometime (The server i request force cache : no cache in headers) ? I am thinking about creating a directory with json file (the api response) for every user id . Or I can go with mysql solution . What's the best solution for me ? N.B : Im getting about 200 000 request/day. Thanks
Upvotes: 0
Views: 430
Reputation: 163593
It sounds like you actually need to optimize this API, so that updates will be there as you expect them to be.
However, if you insist that caching is appropriate for your use, there's no need to reinvent the wheel. Simply put Nginx, Varnish, etc. in front of the API server. Then configure your application to request from this caching proxy rather than the API server directly.
See also:
Upvotes: 1