How to cache JSON data instead of accessing the REST endpoint

json, restful-architecture

Solution

You are using REST, so basically you can cache HTTP requests / responses using a simple HTTP reverse proxy with Apache HTTP, NGINX or Varnish for instance. Why bothering with NoSQL for a simple cache?

Of course MongoDB and Redis provide a lot more functionnalities but do you really need them? Look at this other question: Caching JSON objects on server side

Problem

http://api.bitcoincharts.com/v1/markets.json (sample example) I am planning to access several REST endpoints as mentioned below for data and at certain times access to some of the endpoints fail because of a connectivity error or the service being non available. I am interested only in the last snapshot of the data. In order to resolve this issue I would like to store the latest snapshot in a data store (preferably NoSQL) say Mongo or Redis and would want to modify the application logic to look at these data sources always instead of the API endpoint. This would always provide predictable data and I intend to run some CRON scripts to pull data regularly from these REST endpoints and store it in the above data sources. ``` http://api.foo.com/v1/foo.json http://api.bar.com/v1/bar.json http://api.baz.com/v1/baz.json ``` - Is there a better approach to resolve this issue? - What storage would be appropriate for storing the JSON as it is and retrieve it for processing. Is it Mongo or Redis?

Original source

Related problems