Title says it all... I'm new to coding and I just want as simple as an answer as it can be. I have a weather api, but it is limited on calls each refresh acts as a call, but the forecast updates daily. Anyway around this to maximize my calls? I can post my js code and html if necessary.
Asked
Active
Viewed 53 times
0
-
1Unless the API itself provides a way to "check for new data" (that does not apply to the limit) and/or provides "long poll capabilities" (Comet, SignalR, etc), such is not possible - because the state of the data is not known unless asking the Source of Truth. However, perhaps a timeout can be maintained and only refresh every 30 (eg) minutes? (Or whatever reasonable time period there is.) – user2864740 Nov 21 '17 at 05:13
-
1`I can post my js code and html if necessary.` - that's how SO works, not "title says it all", because in fact, title says very little to those of us without telepathic abilities - `as simple as an answer as it can be`, use `localStorage` or `cookie` to store the last time weather api was called by the browser ... or, if your call is via your server, cache responses on your server – Jaromanda X Nov 21 '17 at 05:18
-
Without your code, there is no answer, because there are several possibilities, and having your code would help determine the best solution – Jaromanda X Nov 21 '17 at 05:28
1 Answers
0
You have two ways. Either you create a database and save all of the data there and retrieve it back when you want to. Or if the data you have is not that much and you don't want to deal with databases, then you write the json string to a text file in the memory card and read it later when you are offline.
And for the second case, every time you go online, you can retrieve the same json from your web service and over write it to the old one. This way you can be sure that you have the latest json saved to the device.
- Use a file to store the API response for the day in server and call the api only once per day(it depends on you how accurate weather details to be shown. twice/ thrice it up to you ).
or you can use any server side language.
- Store the API details in server database and run the API only once a day using a cron file.

Cruzer
- 405
- 5
- 13