How to invalidate cache on Google Cloud Bucket in php code
Get the solution ↓↓↓i'm using Google Cloud Bucket as CDN. When i upload an image to CDN, i setcache-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?
Answer
Solution:
Neither the PHP API client nor the JSON API expose this admin method
... therefore one could only wrap the 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>";
}
Answer
Solution:
This solution doesn’t use Google Cloud PHP, however if you check out this link, you may find the answers you are looking for.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: to enable extensions, verify that they are enabled in your .ini files
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.