Back to Home
Question 5: Content not Being Cached
Customer Inquiry
Subject: Content not Being Cached
After activating Cloudflare on my site, I am seeing that resources on my pages are not being cached. Why is Cloudflare’s caching not working on my site?
curl -svo /dev/null roskolniv.us
* Rebuilt URL to: roskolniv.us/
* Trying 104.16.27.128...
* Connected to roskolniv.us (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.40.0
> Host: roskolniv.us
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 22 Jun 2015 03:03:59 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0
< Strict-Transport-Security: max-age=10
< X-Powered-By: Express
< Server: cloudflare-nginx
< CF-RAY: 1fa4b922fef517a4-SIN
Response to Customer
Hello,
Thank you for providing the output from your "curl" command. It's very helpful!
The reason your content is not being cached is because of the "Cache-Control" header being sent by your origin server.
The header "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, max-age=0".
It explicitly tells Cloudflare including other cache, not to cache the content.
By default, Cloudflare respects the caching headers sent by your origin server. To resolve this, you have two options:
- Modify the Cache-Control headers on your origin server: This is the recommended approach.
You should configure your web server (e.g., Express, as indicated by the "X-Powered-By" header) to send more cache-friendly headers for your static content.
For example, "Cache-Control: public, max-age=3600".
- Use Cloudflare Page Rules: If you are unable to modify the headers on your origin, you can use a Cloudflare Page Rule to override them.
You can create a Page Rule for the resources you want to cache.
You can set the "Cache Level" to "Cache Everything" and set an "Edge Cache TTL" to control how long Cloudflare will cache the resources.
Please let me know if you have any questions about implementing either of these solutions.
Best regards,
João Estêvão
Customer Support Engineer
Cloudflare
Thought Process
- Analyze the Provided Output:
The customer gave me a golden ticket: the "curl" output. The "Cache-Control" header is the smoking gun. My first step is to identify that as the root cause.
- Explain the "Why":
I need to explain that Cloudflare is working as designed by respecting the origin's cache headers. This is important to build trust and show that Cloudflare is not broken.
- Provide Actionable Solutions:
I should provide clear, actionable solutions. In this case, there are two main paths: fix it at the source (origin server) or override it at the edge (Cloudflare Page Rules).
Tools I Would Use
- cURL:
- The customer already used this, but I would use it myself to confirm their findings.
"curl -svo /dev/null -H "Pragma: no-cache" -H "Cache-Control: no-cache" http://roskolniv.us/" would be my command.
It ensures I'm getting a fresh response and not a cached one on my end.
- Internal Cloudflare Dashboard:
- I would check the "Caching" and "Page Rules" sections of the customer's Cloudflare dashboard.
I would look to see if they have any existing Page Rules that might be interfering, or if their "Browser Cache TTL" setting is unusual.