Google cloud storage 谷歌云存储:如何重置边缘缓存?

Google cloud storage 谷歌云存储:如何重置边缘缓存?,google-cloud-storage,Google Cloud Storage,我更新了一个图像(来自PHP),但仍然下载了图像的旧版本 如果我在GCS控制台上下载映像,我可以下载映像的新版本。但是,下面的url返回旧版本 名称]/sample-image.png 这张老照片似乎在谷歌的边缘缓存中 有些文章说,我应该删除图像对象,然后插入新的图像对象,以便清除边缘缓存 有人知道这件事吗 更新1 这是我在GCE上的PHP代码 $obj = new \Google_Service_Storage_StorageObject(); $obj->setName($path

我更新了一个图像(来自PHP),但仍然下载了图像的旧版本

如果我在GCS控制台上下载映像,我可以下载映像的新版本。但是,下面的url返回旧版本

名称]/sample-image.png

这张老照片似乎在谷歌的边缘缓存中

有些文章说,我应该删除图像对象,然后插入新的图像对象,以便清除边缘缓存

有人知道这件事吗


更新1

这是我在GCE上的PHP代码

$obj = new \Google_Service_Storage_StorageObject();
$obj->setName($path . "/" . $name);

$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL);

$storage = new \Google_Service_Storage($client);
$bucket = 'sample.com';

$binary = file_get_contents($_FILES['files']['tmp_name']);
$fileInfo = new finfo(FILEINFO_MIME_TYPE);
$mimeType = $fileInfo->buffer($binary);

$storage->objects->insert($bucket, $obj, [
    'name' => $path . "/" . $name,
    'data' => $binary,
    'uploadType' => 'media',
    'mimeType' => $mimeType,
]);
似乎只有这些参数是有效的。我想我不能设置任何缓存设置

// Valid query parameters that work, but don't appear in discovery.
private $stackParameters = array(
    'alt' => array('type' => 'string', 'location' => 'query'),
    'fields' => array('type' => 'string', 'location' => 'query'),
    'trace' => array('type' => 'string', 'location' => 'query'),
    'userIp' => array('type' => 'string', 'location' => 'query'),
    'quotaUser' => array('type' => 'string', 'location' => 'query'),
    'data' => array('type' => 'string', 'location' => 'body'),
    'mimeType' => array('type' => 'string', 'location' => 'header'),
    'uploadType' => array('type' => 'string', 'location' => 'query'),
    'mediaUpload' => array('type' => 'complex', 'location' => 'query'),
    'prettyPrint' => array('type' => 'string', 'location' => 'query'),
);

我试过这种方法,但到目前为止还没有成功。这是只给GAE的。。。?(或可能需要安装)


我想我终于找到了

$obj->setCacheControl('no-cache')

更新3

$bucket_name = 'my-bucket';
$file = "xxx.html";
$infotowrite = "999";
$service = new Google_Service_Storage($client);
$obj = new Google_Service_Storage_StorageObject();
$obj->setName($file);
$obj->setCacheControl('public, max-age=6000');
$results = $service->objects->insert(
        $bucket_name,
        $obj,
        ['name' => $file, 'mimeType' => 'text/html', 'data' =>   $infotowrite, 'uploadType' => 'media']
);

我们可以检查结果

gsutil ls -L gs://...

默认情况下,如果所有匿名用户都可以公开访问对象,并且您没有指定cacheControl设置,则GCS将提供3600秒或1小时的cacheControl标头。如果您得到的是陈旧的对象数据,并且没有弄乱缓存控制设置,那么我假设您提供的是可公开访问的对象。不过,我不确定谷歌本身是否在缓存您的对象数据,或者您和谷歌之间是否存在其他缓存

将来,您可以通过显式设置较短的缓存控制头来解决此问题,可以使用cacheControl设置对每个对象进行控制

现在,您可能可以通过附加一些额外的URL查询参数来解决这个问题,比如?ignoreCache=1


更多信息:

您是否已清除浏览器缓存?(使用ctrl-f5)嗨。是的,我清除了浏览器缓存。(我还尝试了秘密模式浏览器,这是禁用缓存)完美。这就是我想知道的。非常感谢。有人说流式上下文创建是一种可能的方式。你这样认为吗?Google API PHP客户端不允许设置缓存设置。你知道有什么解决办法吗?“?ignoreCache=1”可以,但我不想更改我的代码。是的,Google也在缓存bucket中的数据,并且此缓存尊重
缓存控制设置,因此默认值为1小时。更新bucket对象后,在缓存过期之前,您可能会随机获得旧对象或新对象。@Crashalot云(和CDN)就是这样工作的。缓存可能分布在世界各地,你永远无法找到理想的解决方案。如果您需要立即更改,请在每次更改时上载一个新对象,并自己在应用程序中分发新对象URL。强制使请求无效的最简单方法是使用GUID值附加一个伪URL查询参数。最规范的正确方法是在请求中包含“Cache-Control:no-Cache”头指令。特别是对于GCS,您可以通过设置对象的
cacheControl
属性来禁用该对象的缓存。
$bucket_name = 'my-bucket';
$file = "xxx.html";
$infotowrite = "999";
$service = new Google_Service_Storage($client);
$obj = new Google_Service_Storage_StorageObject();
$obj->setName($file);
$obj->setCacheControl('public, max-age=6000');
$results = $service->objects->insert(
        $bucket_name,
        $obj,
        ['name' => $file, 'mimeType' => 'text/html', 'data' =>   $infotowrite, 'uploadType' => 'media']
);
gsutil ls -L gs://...