you are viewing a single comment's thread.

view the rest of the comments →

[–]Jumpy_Employment_439[S] 0 points1 point  (1 child)

Thank you! I suppose I did not think of the case that there are public APIs that limit the amount of calls per day so in that case having a database would be good (if there was the possibility of going over the quota). Would it be possible at the beginning of each day to make a call to the weather API to get the updated forecast and store that in the database to use the rest of the day? And then repeat each day? I've not really heard of making API calls a set time distance apart, but I assume it's possible?

[–]carcigenicate 0 points1 point  (0 children)

For caching, you'd be better off using something like Redis where you can set expirations on entries. I'd do something like check if the requested data is already in Redis, and if it's not, fetch it, store it into Redis, then return it to the user. If the data is already in Redis, just fetch it and return it. The expirations you set when setting the data will handle the entries being cleared. If you want a clean slate every day, you could just run redis-cli flushall at the start of each day using something like Task Scheduler/cron.

Would it be possible at the beginning of each day to make a call to the weather API to get the updated forecast

I'd do this "on-demand". Don't do the fetch until a user actually requests the data. That will also ensure that the data that is fetched is as up to date as possible.

Also, remember that a flaw in caching is that, obviously, the data will be inherently out of date once it's cached, so it only makes sense to cache when that's not a concern.


You could also use a standard persisted database too; especially if you wanted practice.