Hello,
I am in the process to understand how to improve Cloudflare cache ratio changing what is required on my blog server side. At the moment I cannot guess anything more and anyway CF hit ratio is quite low.
I made a very simple test using curl to get response header of one static resource from the same IP every 15 seconds for about one hour monitoring the age field using this script:
for i in {1..240}
do
echo $(date -u) >> log/cloudflare_test.log
curl -I https://lamiacasaelettrica.com/wp-content/uploads/2021/08/cropped-la-mia-casa-elettrica-logo-192x192.png | grep age: >> log/cloudflare_test.log
sleep 15
done
One sample response header is the following
HTTP/2 200
date: Tue, 17 Aug 2021 12:04:42 GMT
content-type: image/png
content-length: 6490
cache-control: public, max-age=31536000
cf-bgj: imgq:85,h2pri
cf-polished: origSize=8395
etag: "20cb-5c892f0b41229"
expires: Wed, 17 Aug 2022 11:41:26 GMT
last-modified: Mon, 02 Aug 2021 12:45:12 GMT
pragma: public
referrer-policy: no-referrer-when-downgrade
strict-transport-security: max-age=31536000; includeSubDomains
vary: Accept
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-powered-by: W3 Total Cache/2.1.6
cf-cache-status: HIT
age: 1395
accept-ranges: bytes
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=C2v86UKTSDfDAvoK%2FL9TTlOPQagL7IPOZAVlReUHsQ4kjQyLAy%2BtMeW%2FJ%2FUKOHzzozYD%2Bgo9UG2WPeQ%2F13s%2FmEouDSTid6yvyDHduN1PMedOLmq5Y4a7G02LnhLvWaxAIl645MY1bnw%3D"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
server: cloudflare
cf-ray: 6802c437399c0e2a-MXP
alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400, h3=":443"; ma=86400
As you can see the resource is “old” and not to be expired as per my server response header:
date: Tue, 17 Aug 2021 12:04:42 GMT
...
expires: Wed, 17 Aug 2022 11:41:26 GMT
last-modified: Mon, 02 Aug 2021 12:45:12 GMT
The resulting graph of age field is the following:
For completeness below you can find also W3 Total Cache WordrPress plugin Cloudflare extension configuration:
The very simple question is: why CF cache is expiring so frequently?
In the sample test maximum age was 2655 seconds (44 minutes).
As per all the configurations it should be really longer time.
Any answer or suggestion would be beneficial. Thanks in advance.