简体   繁体   中英

How to invalidate cache on Google Cloud Bucket in php code

i'm using Google Cloud Bucket as CDN. When i upload an image to CDN, i set cache-control: public, max-age=31536000 (365 days). Then i want to replace that image by another one, but i don't know how to invalidate the old cache. I'm using Google Cloud PHP Client SDK https://github.com/googleapis/google-cloud-php .

I tried to delete the old image and upload a new image but it didn't work. I still get the old version.

Does anyone know about this?

Neither the PHP API client nor the JSON API expose this admin method

... therefore one could only wrap the gcloud command with PHP-CLI:

function clear_cdn_cache($urlmap_name) {
    $cmd = 'gcloud compute url-maps invalidate-cdn-cache '.$urlmap_name.' --path "/*"';
    $stdout = shell_exec($cmd); 
    echo "<pre>$stdout</pre>";
}

This solution doesn't use Google Cloud PHP, however if you check out this link , you may find the answers you are looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM