HTTP cache
The API client cache is an excellent mechanism for reducing the load on the server and bandwidth consumption. All browsers have a cache mechanism that stores responses from the server and uses them when the same request is made again. But it is hard for the browser to know exactly what can be cached and for how long. Browsers have their own policy. Sometimes, it can mean requesting again without a need, and sometimes, it means using the cache and missing something that has changed in the server. To help the browser, HTTP provides a set of headers that allow us to control how caching is done from the API. As an API developer, you can leverage those to avoid hitting the API from the client when it is not needed. Let’s start exploring how we control the cache.
Cache control
We can use multiple headers to control the cache, but the most important is the Cache-Control header. It defines the caching policy for the response sent to the user. It accepts multiple...