【发布时间】:2020-06-04 11:57:45
【问题描述】:
我们正在 Google CDN 中缓存我们的页面和内容。
Google 为我们提供了一个 API,可以使特定页面/路径的缓存失效。
我们的网站是使用称为 AEM(Adobe Experience Manager)的 CMS 构建的,该 CMS 支持不断的页面/内容更新,例如。我们可能会在一天内更新两次https://our-webpage/homepage.html 上显示的内容。完成此类操作后,需要刷新 Google CDN 中 "homepage.html" 的缓存。
这种活动很常见,这意味着我们需要在一天内发送几个缓存失效请求(数千个)。
我们发送了如此多的失效请求,以至于一段时间后我们收到此错误
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "usageLimits",
"message" : "Rate Limit Exceeded",
"reason" : "rateLimitExceeded"
} ],
"message" : "Rate Limit Exceeded"
}
我们如何解决这个问题?
我已阅读此页面https://developers.google.com/drive/api/v3/handle-errors
它提到了批处理请求。
如何将多个页面的失效请求一次性发送到 Google CDN?
或者是否可以将 API 刷新调用限制增加或设置为每天更高的数量。
现在,如果我们有 100 个页面要从 CDN 刷新,我们会进行 100 次以下 HTTP 调用(每个页面一个)。
CacheInvalidationRule requestBody = new CacheInvalidationRule();
// IMPORTANT
requestBody.setPath(pagePath);
Compute computeService = createComputeService();
Compute.UrlMaps.InvalidateCache request =
computeService.urlMaps().invalidateCache(projectName, urlMap, requestBody);
Operation response = request.execute();
if(LOG.isDebugEnabled()) {
LOG.debug("Google CDN Flush Response JSON :: {}",response);
}
LOG.info("Google CDN Flush Invalidation for Page Path {}:: Response Status Code:: {}",pagePath,response.getStatus());
我们将页面设置为刷新requestBody.setPath(pagePath);
我们能否以一种更有效的方式来做到这一点,例如在一次 HTTP 调用中将所有页面作为数组或字符串发送?
喜欢:
requestBody.setPath(pagePath);
在哪里
pagePath="['/homepage.html','/videos.html','/sports/basketball.html','/tickets.html','/faqs.html']";
【问题讨论】:
标签: java google-api aem