Card 10/ 11

ExerciseDifficulty: Advanced1 min

Practice: Caching Headers for Five Endpoints

A product list, a user's profile, an exchange rate, a password reset and an editable document.

Choosing caching headers means asking who may store each response, for how long, and whether writes need a version check. For each endpoint, choose the response headers and say why.

  1. GET /products, public, changes a few times a day.
  2. GET /me, the signed-in user's profile.
  3. GET /rates/EUR-USD, an exchange rate updated every minute.
  4. POST /password-resets, which returns a one-time reset token.
  5. GET /documents/9, a document several users edit with PUT.
Show the answers
Each endpoint, its headers, and the reason
EndpointHeadersWhy
GET /productsCache-Control: public, max-age=600, and an ETagShared caches may hold it; ten minutes stale is acceptable
GET /meCache-Control: private, no-cache, and an ETagOnly the user's browser may keep it, and it is checked each use
GET /rates/EUR-USDCache-Control: max-age=30Short freshness absorbs bursts without serving minute-old rates
POST /password-resetsCache-Control: no-storeA secret must never be kept by any cache
GET /documents/9Cache-Control: private, no-cache, and a strong ETagRevalidated reads, and the ETag goes back in If-Match on each PUT

For the document, the server also answers a PUT with no If-Match with 428 Precondition Required, and a stale one with 412.