I'm creating an end point that gives the current traffic conditions and the temperature. It combines data from two endpoints:
- GET current traffic statistics (at every request)
- GET current temperature (every 3 hours)
A simple solution would be to chain two promises together, but I don't need to call 2. at every request. How could I structure my code to hold the data for 2. and refresh it periodically?
create temperature module with current temperature value, setInterval to update this value every 3 hours.
On your endpoint make request for traffic data, and read cached value from temperature module.