简体   繁体   English

如何在 php 代码中使 Google Cloud Bucket 上的缓存失效

[英]How to invalidate cache on Google Cloud Bucket in php code

i'm using Google Cloud Bucket as CDN.我正在使用 Google Cloud Bucket 作为 CDN。 When i upload an image to CDN, i set cache-control: public, max-age=31536000 (365 days).当我将图像上传到 CDN 时,我设置了cache-control: public, max-age=31536000 (365 天)。 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 .我正在使用谷歌云 PHP 客户端 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 PHP API 客户端和 JSON ZDB974238714CA8DE634A7CE1D083A14F 均未公开此管理方法

... therefore one could only wrap the gcloud command with PHP-CLI: ...因此只能使用 PHP-CLI 包装gcloud命令:

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.此解决方案不使用 Google Cloud PHP,但是如果您查看此链接,您可能会找到您正在寻找的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用php将文件上传到Google云存储中存储桶中的子文件夹 - how to upload file to subfolder in bucket in google cloud storage using php PHP页面的简单缓存代码失败-提交表单时如何使缓存无效 - Simple Caching code for PHP Pages Fails - How to invalidate cache when form is Submitted 如何仅使用 OAuth 2.0 不记名令牌和存储桶名称在谷歌云存储中生成文件的签名 URL? (PHP代码) - How to generate a Signed URL of file in google cloud storage with just OAuth 2.0 bearer token and bucket name? (php code) Google Cloud Storage 对存储桶中的对象进行分页 (PHP) - Google Cloud Storage paginate objects in a bucket (PHP) Google云端存储-无效的存储桶名称(PHP) - Google Cloud Storage - Invalid bucket name (PHP) 使用 PHP 从 Google Cloud Bucket 加载图像 - Loading an image from Google Cloud Bucket with PHP 在谷歌云存储桶中运行 PHP - Run PHP in Google Cloud Storage Bucket 在 Google Cloud Storage 存储桶上设置缓存控制 - Set Cache-Control on Google Cloud Storage bucket 是否可以仅使用 Authorization Bearer Token 和 Bucket 名称将文件上传到谷歌云存储? (PHP代码) - Is it possible to upload files to google cloud storage with just Authorization Bearer Token and Bucket name? (php code) PHP代码读取上传到谷歌应用引擎云存储桶的excel文件 - PHP code to Read excel file uploaded to google app engine cloud storage bucket
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM