Google Cloud Storage file cache and expiry issue

2019-07-09 05:30发布

问题:

Suddenly I noticed that one config file stored in Google Cloud Storage bucket has 2019 as the expiry! (Update: Noticed 1year expiry is nothing new for this) All had worked fine for years until I noticed this issue today.

Its a public file and was always being written to cloud storage with "no-cache". Somehow I noticed that probably there was a mistake in the way it was being written since I see the header now shows "Cache-Control: Cache-Control:no-cache" instead of just "Cache-Control:no-cache". Surprising it worked all these years.

curl -I reports:

Date: Tue, 03 Apr 2018 16:35:56 GMT
Expires: Wed, 03 Apr **2019** 16:35:56 GMT
Last-Modified: Tue, 03 Apr 2018 10:36:19 GMT
Content-Type: application/json
...
Accept-Ranges: bytes
Content-Length: 40032
Server: UploadServer
Cache-Control: Cache-Control:no-cache
Age: 339750

I have tried overwriting this file, and delete and upload again to no avail. Is there a solution to make it use the latest content? (Last option is to rename the file, but then all my existing Apps which read this file will have a problem).

I am not even sure how suddenly the cached file got an expiry of 2019 even though this file is pretty much changed every day by our server.

Edit: And no matter what I do, the Last-Modified now does not seem to change, even if I write programmatically using GCS library (which our server users) or with gsutil;

gsutil -h "Cache-Control:no-cache" cp config.json gs://<server>.appspot.com/config/; gsutil acl set public-read gs://<server>.appspot.com/config/config.json

So no matter how many times I update or write the file, the Date/Last Modified time stamps dont change, nor the content.

Thanks!

回答1:

The gsutil docs at [1] mention using the value "private" to prevent caching of publicly readable objects. Do you still see this behavior when using "Cache-Control:private"?

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