Before we begin, let's recap the features that we want to implement:
- The server should notify the client
- Notifications should be pushed only if the reading changes
The first requirement means that we have to replace our /temperature and /humidity API calls with their socket notification equivalents. The second requirement means that we need a way to link our implementation of the first requirement with a mechanism to only push notifications when a reading changes:
It is generally a good practice to make sure that each module in our application functions independently and has only one job that it does well. Following this, it would be unwise to have our cache module communicate with the socket connection directly since:
- It is not either of their jobs to do so.
- This would cause problems in the future if we had...