2

I'd like to create a smart cache for my weather forecast API requests (temperature, wind, etc. for a given point).

I query the forecast provider by specifying coordinates of the point I want to get the data from. Sometimes, I query the same points over and over again or some nearby points and I'd like to make fewer requests to the forecast provider.

I thought about dividing the globe into tiles as they do on maps (eg. OpenStreetMap / Google Maps).

When the forecast is requested I would calculate the tile's x & y from the inputted coordinates and check if I have any recent forecast data stored in this tile.

Then:

  • If there are no points found, I would make a request to my forecast provider.
  • If a point is found in the requested tile, I would return that point's data.

After making a request to my weather forecast API provider, I would store the received data in my InfluxDB with a tile's x & y numbers and coordinates.

Is there a better way to cache it?

Defozo
  • 2,946
  • 6
  • 32
  • 51

0 Answers0