POST requests can be cached only within narrow limits, because RFC 9110 requires an explicit freshness indication and a Content-Location field containing the target URI of the request. A response stored this way can serve later GET or HEAD requests. It never serves further POST requests. In practice, according to RFC 9110, the overwhelming majority of cache implementations support only GET and HEAD anyway.
A cache builds on the principle of request and response of an API and sits between the calling client and the server that produces the response. RFC 9111 “HTTP Caching” describes it as local storage for response messages, together with the subsystem that controls storing, retrieving, and deleting them. A cache keeps cacheable responses to reduce response time and bandwidth for later equivalent requests.
Every incoming request goes through the same check in the cache:
- The cache builds a key from the method and the target URI and uses it to look up a stored response.
- If it finds none, the result is a cache miss: the request goes to the server, and the cache stores the server’s response if its headers allow it.
- If a fresh response is stored, the cache serves it right away as a cache hit.
- If the stored response is stale, the cache asks the server whether it is still valid.
A response is fresh as long as its age has not exceeded its freshness lifetime. After that, it counts as stale. Reusing stored responses is the default behavior in HTTP unless a directive says otherwise.
How much does a cache take load off the backend? The hit rate decides, because only misses and revalidation requests reach the server. If a database can handle only a few simultaneous connections, a shared cache can answer requests even when all connections are in use.
Because many API gateways cache responses themselves, caching is one of the policies that protect backend services from unnecessary calls. Together with a management plane, a developer portal, and analytics, the gateway forms an API management platform.
