Our next problem is that we do not want to actually call our sensor interface every time someone requests the temperature and humidity through our API. To solve this, we need to cache our results.
In simple terms, this means that we need a temporary form of storage for the latest results. Whenever we receive a request, we will return results from this temporary storage, and not call the native sensor interface. In the background, we will periodically (the same period as the sensor) obtain readings from the sensor and update the cache.
Caching our results also provides us with other benefits:
- Our server becomes much faster since the results are obtained directly from local memory rather than having to be read from the ...