0

I have uploaded file to google cloud storage via their php API

I am trying to use following code now to access it back.

$bucket = $storage->bucket('my-bucket');
$object = $bucket->object('filename.json');
$string = $object->downloadAsString();
echo $string;

I am just trying to retrieve a json , But problem is its getting cached and keep giving me old file which I modified 30 mins back.

How to disable Cache ? While using downloadAsString ?something like

https://storage.googleapis.com/my-bucket/filename.json?id=randomtimestamp

P.s: I know Disabling cache while uploading json will work, but I just want to disable cache in few of my php scripts.

Gracie williams
  • 1,287
  • 2
  • 16
  • 39
  • if you have Google storage utility (https://cloud.google.com/storage/docs/gsutil_install) installed then you can use the following command to set cache control headers for selected file using this command `gsutil -m setmeta -h "Cache-Control:private, max-age=0, no-transform" gs:////` eg. `gsutil -m setmeta -h "Cache-Control:private, max-age=0, no-transform" gs://bucket134/javascripts/load.js` – Yogesh Patil Feb 20 '18 at 05:28
  • Please read my P.s – Gracie williams Feb 20 '18 at 08:41
  • Above mentioned command is not needed to run at the time of upload. You can do it anytime. Second, check if you have versioning enabled on your bucket. If yes then try to switch it off if possible. – Yogesh Patil Feb 21 '18 at 05:31
  • You can set this URL query parameter, like `?ignoreCache=1` with reference to https://stackoverflow.com/a/37124554/1578466 answer. – Yogesh Patil Feb 21 '18 at 05:38
  • how to use ignoreCache parameter inside downloadasstring funciton ? in php api ? – Gracie williams Feb 21 '18 at 09:21
  • I am not much familiar with PHP but check if this answer helps you https://stackoverflow.com/a/32233553/1578466 – Yogesh Patil Feb 22 '18 at 05:40
  • To get a broader context for the ?ignoreCache=1 URL query parameter, one may refer to the the [Cloud Storage XML API](https://cloud.google.com/storage/docs/xml-api/overview) : a RESTful interface that lets you manage Cloud Storage data in a programmatic way. – George Feb 27 '18 at 20:53

0 Answers0