Request 'no-cache' header is ignored by Cloudflare

Cloudflare ignores request cache headers. Is this by design?
Details:
I have a subdomain cache.example.tld with one rule:

cache.example.tld/*
Cache Level: Cache Everything, Origin Cache Control: On

The server responds with a cache header Cache-Control: public

Now there are times when I would like to make cloudflare refresh the cache. I think the standard way is to make a request that asks for a fresh copy as follows:

`curl -v " cache.example.tld/?id=x" -H “Cache-Control: no-cache”

To my surprise cloudflare server returns stale data. Even in the headers is clear that it doesn’t try to fetch a new copy from the origin(cf-cache-status: HIT). Is there any reason for this broken behaviour?

``

Host: cache.example.tld
User-Agent: curl/7.64.1
Accept: /
Cache-Control: no-cache

  • Connection state changed (MAX_CONCURRENT_STREAMS == 256)!
    < HTTP/2 200
    < date: Sat, 29 Aug 2020 15:19:56 GMT
    < content-type: application/json
    < content-length: 32360
    < set-cookie: __cfduid=daeefeafaba86b507708ca72025256faa1598714396; expires=Mon, 28-Sep-20 15:19:56 GMT; path=/; domain=.example.tld; HttpOnly; SameSite=Lax
    < access-control-allow-credentials: true
    < access-control-allow-origin:
    < access-control-expose-headers: content-type, link, WWW-Authenticate, Server-Authorization
    < cache-control: public, max-age=14400
    < cf-cache-status: HIT
    < age: 683
    < accept-ranges: bytes
    < cf-request-id: 04dc66d85b00002948b280a200000001
    < expect-ct: max-age=604800, report-uri=" report-uri.cloudflare.tld/cdn-cgi/beacon/expect-ct"
    < server: cloudflare
    < cf-ray: 5ca740d3ce7b2948-OTP
    <
    { [921 bytes data]
    100 32360 100 32360 0 0 57580 0 --:–:-- --:–:-- --:–:-- 57477
  • Connection #0 to host cache.example.tld left intact
  • Closing connection 0
    ``

A client being able to bypass the cache would be pretty troublesome for security since then someone could DOS a server by flooding the server with no-cache requests.

You should use the CF API to purge the cache.

3 Likes