2

I have set up a GCP Cloud CDN with a backend bucket. My problem is sometimes cacheable contents are not getting cached.

For example, when I open an image in the bucket on Firefox or Chrome with the following in the response the image doesn't get cached:
Status: 200
Cache-Control: public,max-age=3600
Content-Length: 313695
which satisfy all requirements listed here: https://cloud.google.com/cdn/docs/caching?authuser=1#cacheability

And my bucket is publicly available with allUsers with Storage Object Viewer permissions enabled.

When I curl -s -D - -o /dev/null http://example/foo/bar/image.jpeg, the image gets cached fine. And images under http://example/foo/ (no more subdirectories) all seem to get cached fine.

Why are my contents not getting cached?

EDIT: Chrome requests except the first one have the status 304 and statusDetails: "response_sent_by_backend" whereas curl requests have statusDetails: "response_from_cache". Also Chrome requests take 80-100ms for a 30kb image and curl gets it in 1ms.

enter image description here

EDIT2: Things are working as intended.

Dokook Choe
  • 266
  • 2
  • 9
  • Unlike curl, Chrome and Firefox both have built-in caches, so the fact that subsequent requests are served from those caches might be confusing your results. What specific evidence of caching are you observing with curl but not with Firefox and Chrome? – elving Aug 28 '22 at 08:01
  • @elving I've added a photo of logs. Chrome's requests are slower than curl's and Chrome requests say `response_sent_by_backend` and curl's say `response_from_cache`. – Dokook Choe Aug 28 '22 at 20:05
  • The requests from Chrome are cached. That is what 304 means. 304 Not modified means that Chrome is checking for updates, not finding one, and delivering from the Chrome cache. **That does not indicate that the object is not cached at the CDN**. The CLI curl is not checking for anything and the CDN is returning from its cache. Based upon the details in your question you do not have a CDN cache problem. – John Hanley Aug 29 '22 at 02:19
  • @JohnHanley I thought if CDN is working I should see `response_from_cache` with `cacheHit: true` ([document](https://cloud.google.com/cdn/docs/setting-up-cdn-with-bucket#verify_that_is_working)). For the examples shown here they were returned with `response_sent_by_backend` and no `cacheHit: true`. – Dokook Choe Aug 29 '22 at 02:55
  • the browser asked the CDN if the object was modified so the CDN went to the backend. You need to issue an object read, not a modified check. Clear the browser cache to confirm. – John Hanley Aug 29 '22 at 03:46

0 Answers0