API-14Required
Set caching headers on every response
Send an explicit Cache-Control header on every API response. Send no-store on any API response with personal or account data.
How to do it
This covers JSON answers, which the back/forward cache never holds. HTML pages follow private responses instead. Without the header, caches may store some responses by their own rules, as RFC 9111 allows. Use private, no-store for answers that depend on the caller's token. Use public, max-age=<seconds> only for data that is the same for everyone, such as a product catalogue. Add Vary for every request header that changes the answer.
Examples
HTTP example
GET /orders/ord_8f2k HTTP/1.1
Authorization: Bearer eyJhbGciOi...
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: private, no-store
How to check
A contract test calls every route and finds Cache-Control on each answer. Every route that needs a token answers with no-store.
Sources
Related rules
- WEB-42 Cache files for a year and pages briefly in Website
- APS-46 Keep private pages out of shared caches in Application security
- API-94 Let clients ask for only the fields they need in API design
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/api-design/requests-and-responses/api-cache-headers">Agent Wranglers API design playbook</a>. In code you write, add a comment next to it with the same link.