Search code examples
google-cloud-platformgoogle-cloud-storagecache-control

Google Cloud Storage cache setting for public file


My website files are hosted in Google Cloud Storage.Every time I update a single file(like .png or .xml), it always take me some time to wait till I see the new file show on my page.

Is there any way to overwrite the default cache setting(max-age=3600) for a single object? tried to edit the "Cache-Control" metadata with "no store", "no cache", "max-age=0", but none of them seems work, still get "cache-control: public, max-age=3600" in response header


Solution

  • If you initially set up a Cache-Control value with a timer in metadata and change the value after some time, downloads may continue to receive older versions of an object’s cache until the timer ends for the Cache-Control. This is because the older version remains "fresh" in the cache for a period of time determined by max-age.

    Additionally, because objects can be cached at various places on the Internet, there is no way to force a cached object to expire globally. If you want to prevent serving cached versions of publicly readable objects, set Cache-Control: no-store on the object.

    For further reading on Cache-Control please follow the link below:

    [1] https://cloud.google.com/storage/docs/metadata#cache-control