liveBook · Manning

Caching

As explained in API Design Patterns

A cache is a stored copy of data retained for faster or more convenient access than retrieving the original data again.

HTTP caching retains a response or resource copy so later access can avoid another retrieval or request. It improves convenience and reduces repeated work, but every copy creates a freshness and consistency decision. section 13.3.3 section 26.3.2

Choose the cache boundary deliberately:

  • Cache a related resource inside another resource when avoiding a second API call matters; then define how the embedded copy stays current. section 13.3.3
  • Use a live reference when freshness is more important than convenience; clients must make another request to retrieve the referenced resource. section 13.3.3
  • For request deduplication, cache the complete response under its request identifier after processing the request, then return it for repeats. section 26.3.2
  • Prefer a straightforward response cache over recalculating results, while setting expiration and invalidation deliberately and accounting for large responses. section 26.3.2 section 26.6

Books and authors

A client can retrieve a book and then issue a second request for its author name. Embedding the Author object in the Book response removes that extra call, but the server must either join current author data for every request or maintain a cached author copy. If the author changes, the embedded value requires a freshness strategy. section 13.3.3

How API Design Patterns covers it

How deep it goes
Explains references, embedded copies, response replay, storage costs, expiration, invalidation, and collision safeguards.
Examples
Demonstrates book-author resources, repeated non-idempotent requests, large batch responses, and pagination result caches.
What it assumes
Assumes API resources and requests, while contrasting references and copies through book-author examples.
What you can do after
Apply it via request identifiers, response caches, embedded resources, and explicit freshness policies.
How it connects
Connects caching with API references, request deduplication, data consistency, pagination, and request identifiers.

Also explained in

Compare how 38 books explain caching →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.