Module 17 Β· Caching Layers β Lesson 1 of 4 Β· ~8 min
HTTP caching for an API
The cheapest response is the one you don't render
Module 16 made queries fewer (.includes) and faster (composite indexes). This module asks a different question: what if the client already has the exact response you're about to build? Re-running the query, re-serializing the JSON, re-sending the bytes β all of that is wasted work if nothing changed since the client's last request.
HTTP has a built-in answer: conditional GET. The server response carries an ETag β a fingerprint of the resource's current state. The client stores it and sends it back on the next request as If-None-Match. If the fingerprint still matches, the server replies 304 Not Modified with no body at all β the client just keeps using the copy it already has.