0

I would like to know how could I set default meta-data for all future uploaded objects.

Am trying to set "Cache-Control:public,max-age=3600" as a header for each object in my bucket hosting a static website. For all the existing objects, I used the guide command to set meta data, although, can't find a way to set it by default for future uploaded objects.

P.S., Developers are using GCP console to upload the objects, and I recently realized that when they upload the updated HTML files (which replaces the one's on bucket), the meta-data resets.

Amit
  • 109
  • 2
  • 2
  • 11

1 Answers1

0

According to the documentation, if an object does not have a Cache-Control entry, the default value when serving that object would be public,max-age=3600.

In the case that you still want to modify this meta-data, you could do that using the JSON API inside a Cloud Funtion that would be triggered every time a new object is created or an existing one is overwritten.

Miguel
  • 956
  • 6
  • 20
  • That's strange. The objects in our bucket did not have any cache-control tags, still, they were not served via CDN (0% utilization). Only after we explicitly ran the setmeta command using gsutil and set the Cache-Control:public,max-age=3600, we saw traffic being served via CDN. – Amit Sep 26 '19 at 09:49
  • That "public,max-age=3600" cache-control will only be served if the object is publicly readable. – Mike Schwartz Sep 26 '19 at 22:16
  • Hi @MikeSchwartz, All the objects in that bucket was publicly readable. Am still trying to find a reason why the traffic wasn't served via the CDN when no cache-control was set. – Amit Sep 27 '19 at 04:23
  • Could you specify where are you seeing this "CDN (0% utilization)" ? My guessing is that the cache was disabled previously to setting the "cache-control" setting, ergo not sending traffic over Cloud CDN. since Cloud CDN is used to cache content close to the end users, according to the documentation description (https://cloud.google.com/cdn/docs/). – Mayeru Oct 02 '19 at 14:34
  • @Mayeru, I could see the % contents served from CDN in GCP CDN Stackdriver. Once I explicitly set this meta-data, it's now around 80-90%... – Amit Oct 12 '19 at 16:38