Course contentsShow
← Web Development
Lesson 1478 of 2,98227. REST API Design for FrontendFree lesson

Cacheability Constraint

How REST responses must explicitly indicate if they can be cached to improve performance.

Cacheability Constraint

What you'll learn: How REST responses must explicitly indicate whether they can be cached to improve performance and reduce server load.

Why Cacheability Matters

In REST architecture, the Cacheability Constraint requires that every response from the server clearly label itself as either cacheable or non-cacheable. This simple rule has huge performance implications.

Think of it like a librarian stamping books: some get marked "reference only—must return tonight" while others get "keep for two weeks." Without these stamps, you'd have to ask the librarian every single time. With them, you know exactly when you can reuse information you already have.

How It Works

When a REST API responds to a request, it includes metadata (usually HTTP headers) that tells the client:

  • Can this response be stored and reused? (Is it cacheable?)
  • How long is it valid? (Cache duration)
  • Under what conditions can it be reused? (Cache validation rules)

If a response is marked cacheable, the client (or intermediate proxies) can store it. The next time that same resource is requested, the cached copy can be returned instantly—no network round-trip needed!

The Benefits

When responses are properly marked as cacheable:

  • Reduced latency – Clients get instant responses from cache
  • Lower server load – Fewer requests hit your backend
  • Better scalability – Your API can handle more users
  • Reduced bandwidth costs – Less data transferred over the network

Non-cacheable responses (like personalized user data or real-time information) are marked as such to ensure clients always fetch fresh data.

Key Takeaway: The Cacheability Constraint requires REST APIs to explicitly declare whether responses can be cached, enabling dramatic performance improvements through reuse while maintaining data freshness when needed.