使后端的Google Cloud CDN缓存无效 [英] Invalidate Google Cloud CDN cache from the backend

查看:282
本文介绍了使后端的Google Cloud CDN缓存无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过几天的研究和阅读文档,我几乎可以肯定这几乎是不可能的,但我仍然想问一下:

After few days of research and reading documentation, I'm almost sure It's nearly impossible, but still I would like to ask:

目标是在不使用该CDN的第三方后端上按需(由于标题更改)使GCloud CDN中的所有缓存内容无效.使用gsuite可以通过以下命令来实现:

The goal is to invalidate all cached content in GCloud CDN on demand (due to headers changes) on the 3rd party backend, which does not use that CDN. Using gsuite it can be achieved by using the following command:

gcloud compute url-maps invalidate-cdn-cache web --path '/*' --async

但是问题在于,此命令要求我们使用客户的凭据通过浏览器登录到Google帐户,这绝对使它一文不值.

But the problem is that this command requires us to login to google account via browser with client's credentials, which makes it absolutely worthless.

一个可悲的故事是,Google似乎为其其他服务提供了相当丰富的API,但对于CDN则没有API:(

The sad story is that it seems Google has pretty rich API for its other services, but for CDN there is no API :(

该想法是接受用户的凭据并使用它们使该缓存无效.甚至有可能吗?

The idea is to accept user's credentials and invalidate that cache using them. Is it even possible?

推荐答案

因此,我对impossibility错了.我找到了相应的REST API方法( https://cloud. google.com/compute/docs/reference/rest/v1/urlMaps/invalidateCache ):

So, I was wrong about impossibility. I found the respective REST API method (https://cloud.google.com/compute/docs/reference/rest/v1/urlMaps/invalidateCache):

POST https://www.googleapis.com/compute/v1/projects/{project}/global/urlMaps/{resourceId}/invalidateCache

这是使用官方gem 的示例Ruby代码. >:

And here is a sample Ruby code to work with it using official gem:

require 'google/apis/compute_v1'

service = Google::Apis::ComputeV1::ComputeService.new
service.authorization =
  Google::Auth::ServiceAccountCredentials
    .make_creds(
      json_key_io: File.open('/path/to/credentials.json'),
      scope:       [Google::Apis::ComputeV1::AUTH_COMPUTE]
    )
service.invalidate_url_map_cache(
   'some-gcloud-project-id',
   'some-url-map',
   nil,
   request_id: SecureRandom.uuid
)

这篇关于使后端的Google Cloud CDN缓存无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆