Is Cache-Control Header for Client or Server?

Iman Tung
1 min readApr 2, 2020

--

My little note on HTTP caching

Image is taken from eBay

Where or how do we handle the caching?

A (web) system has a lot of tiers.

  1. Client-Side Caching
    Browsers cache the data in its local storage
  2. Intermediary Caching
    Intermediaries are something between client and server (RFC7230) like proxy or gateway. Cache mechanism is handled by Nginx, Varnish or another caching-proxy.
  3. Server-Side Caching
    Backends cache the database inquiry or communication to some vendors.

Can we control it?

The best practice is using cache-directive (Cache-Control header).

Using cache-directive, you can:

  • Modify the expiration time
  • Decide to store/cache or not
  • Revalidate/reload the data

Combining with question #1. Is Cache-Control for client, intermediary or server? The answer is mentioned in RFC2616

The Cache-Control general-header field is used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain.

Conditional Request

Additionally, we can use a conditional request (ETag and If-Not-Match headers). The client simply handle 304 Not Modified which is return by the server when it has no new data.

Learn More

--

--

Iman Tung
Iman Tung

Written by Iman Tung

Technology to write, life to grateful. Overthinking is good, only if it has the output. Fundamental is the main concern.

No responses yet