Cloudflare inconsistent caching for images served from Azure

Hi Guys, we’ve been using Cloudflare for several years and all has been working correctly. We recently moved our images off of our server and into an Azure storage bucket with Azure CDN in front of it, we still want to use Cloudflare to serve our images where possible as they have the fastest response time we have seen.

The caching seems inconsistent though, I have set the headers on both our side and Azure side to cache for 1 year. When I go to a fresh page I get cache MISS on all images as expected, on refresh I get cache HIT on all images, also as expected, however when I go back a few days later some of the images are MISS again and some are HIT with an age figure corresponding to when I cached the page myself. We arent purging anything from the cache and all images have the same headers sent so I’m a bit confused, has anyone else encountered this?

I can see mention of a 24h cache in the alt-svc header but I’m not sure where that is set or how I would change it. I proxy image requests through nginx to the Azure CDN URL does that potentially have something to do with it? Overall I would be less confused if it just didnt work at all but some images working and others not seems odd, all images work at first and then some seem to drop off later but not all.

Example request:

accept-ranges: bytes
alt-svc: h3-27=“:443”; ma=86400, h3-28=“:443”; ma=86400, h3-29=“:443”; ma=86400, h3=“:443”; ma=86400
cache-control: max-age=31536000
cache-control: public
cf-cache-status: MISS
cf-ray: 666e187dc9650782-LHR
cf-request-id: 0af8ada2a100000782d5104000000001
content-length: 5950
content-md5: y3Oj4ywzRq5z5WOHrvQpQw==
content-type: image/jpeg
date: Tue, 29 Jun 2021 09:23:22 GMT
etag: 0x8D921D155555988
expect-ct: max-age=604800, report-uri=“https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct
expires: Wed, 29 Jun 2022 09:23:22 GMT
last-modified: Fri, 28 May 2021 12:08:41 GMT
nel: {“report_to”:“cf-nel”,“max_age”:604800}
pragma: public
report-to: {“endpoints”:[{“url”:“https://a.nel.Cloudflare.com/report/v2?s=1zopWiu4WPHMTKDO%2FsKWczhMuFeW9pKupHqcZIDiDxL8T2kO1ojgX2zX%2BlcKBL5p3fHxRaS3GCS6Ka0AmWc14NZnmFtXSG0XsiaAWRX2BpFrYsnhZG%2BTgY3JNFwNFQ%3D%3D”}],“group”:“cf-nel”,“max_age”:604800}
server: Cloudflare
vary: Accept-Encoding
x-azure-ref: 0iebaYAAAAADgpYdqbI6cSqVuUJTfmKLlTE9OMjFFREdFMTUyMgA2NWFkOGY2OC04NGYyLTRhZWYtYjY5OC0yYjMzZDJhMzllZjg=
x-cache: TCP_MISS
x-ms-blob-type: BlockBlob
x-ms-lease-status: unlocked
x-ms-request-id: b3893ca7-801e-0047-50c8-6c5115000000
x-ms-version: 2009-09-19

Kind Regards
Miles

This is expected behaviour. Cache-Control defines a max-age, not an exact-age. Cloudflare will evict objects from the cache if they are not popular. Paid plans are less likely to be evicted, but objects which are not being accessed will still be subject to eviction. (The solution is to make sure your images are really popular!)

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.