The command
curl -H "Cache-Control: no-cache" -H "Pragma: no-cache" https://httpbin.org/cache
Opens the request console with this request filled in. It is sent from api-tester.com's server rather than from your machine, so it shows what the endpoint returns, not how your own network or curl build behaves.
What the flags do
| Flag | What it does |
|---|---|
-H "Cache-Control: no-cache" | Asks caches to revalidate with the origin before answering. |
-H "Pragma: no-cache" | The HTTP/1.0 equivalent, still honoured by some old proxies. |
-I | Show the response headers that reveal whether a cache answered. |
--etag-save / --etag-compare | Store an ETag and send it back as If-None-Match (curl 7.68+). |
Did a cache answer?
Look at the response headers. Age is the number of seconds the response has been sitting in a cache; its presence means you did not get a fresh copy. CDNs add their own markers, commonly X-Cache: HIT or MISS, or a vendor-specific equivalent. Compare a normal request with a no-cache one and watch those values change.
curl -sI https://example.com/app.js | grep -i -E "^(age|x-cache|cache-control|etag)"
curl -sI -H "Cache-Control: no-cache" https://example.com/app.js | grep -i -E "^(age|x-cache)"
When the header is ignored
A request header is a request. Many CDNs are configured to disregard client Cache-Control, precisely so visitors cannot force traffic to the origin. Two things still work. A unique query string makes a URL the cache has never seen, as long as the cache key includes the query. Purging through the CDN's own API or dashboard is the reliable option.
curl "https://example.com/app.js?nocache=$(date +%s)"
Conditional requests
The opposite goal, downloading only when something changed, uses validators. Send the ETag from last time as If-None-Match and an unchanged resource answers 304 Not Modified with no body. Curl automates the bookkeeping with two flags.
curl --etag-save etag.txt --etag-compare etag.txt -o data.json https://example.com/data.json
Common mistakes
no-cachedoes not mean "do not store". It means "revalidate before use". The directive that forbids storing isno-store, and it belongs on responses.- These headers do nothing to your browser's cache. They only affect the request curl is making.
- Cache-busting query strings fail on CDNs set to ignore the query when building the cache key.
Related curl examples
Curl Send Header Example
-H adds a header line to the request.
Curl HEAD Request Example
HEAD asks for the headers a GET would return and nothing else.
Curl Keep-Alive Example
"Keep-alive" names two unrelated mechanisms, and curl has switches for both.
Curl GET Request Example
GET is what curl does when you give it nothing but a URL.
All Curl Examples
49 worked examples, grouped by what you are trying to do.
More under Headers
References
- curl man page: -H — Adding the Cache-Control and Pragma request headers.
- MDN: Cache-Control — Every directive, for requests and for responses.
These links leave api-tester.com, which is independent of the projects they point to.
FAQ
How do I disable caching in a curl request?
Add -H "Cache-Control: no-cache" and, for old proxies, -H "Pragma: no-cache". Curl itself does not cache, so this targets CDNs and proxies between you and the server.
Does curl cache responses?
No. Curl has no response cache. A stale result comes from an intermediate cache such as a CDN or proxy.
How can I tell whether a response came from a cache?
Inspect the response headers with curl -I. An Age header or a marker such as X-Cache: HIT indicates a cached copy.