How to combine data from two end points that don't need to be called the same amount of times? [nodejs]

22 views Asked by At

I'm creating an end point that gives the current traffic conditions and the temperature. It combines data from two endpoints:

  1. GET current traffic statistics (at every request)
  2. 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?

1

There are 1 answers

0
Kieper On BEST ANSWER

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.