- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的项目中,每当调用 API 时,它都会缓存在 Akamai 中。但是当客户端通过 UI 更改数据库中的某些内容时。我们需要使 AKAMAI 中缓存的 API 响应失效,并用新的新鲜 json 数据填充它。我在互联网上找到了一些链接:akamai-purging但我无法理解他们正在谈论的这个链接中的 cp-code 是什么?
这是我的示例代码,给出:405 不允许
代码:
public static void main(String[] args) throws IOException, RequestSigningException {
URL url = new URL("https://xxx-host-name-/scripts.4535eaf743502b25ba3a.js");
HttpTransport HTTP_TRANSPORT = new ApacheHttpTransport();
HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory();
AkamaiPostData postData = new AkamaiPostData();
postData.setHostname(AkamaiConstants.SITE_HOST_NAME);
Gson gson = new Gson();
String postDataJSON = gson.toJson(postData);
byte[] contentBytes = postDataJSON.getBytes();
HttpContent content = new ByteArrayContent("application/json", contentBytes);
HttpRequest request = requestFactory.buildDeleteRequest(new GenericUrl(url));
HttpHeaders headers = request.getHeaders();
headers.set("Host", "xxx-host-name-");
ClientCredential credential = new DefaultCredential(AkamaiConstants.CLIENT_TOKEN, AkamaiConstants.ACCESS_TOKEN, AkamaiConstants.CLIENT_SECRET);
RequestSigner signer = new EdgeGridV1Signer(Collections.EMPTY_LIST, 1024 * 2);
HttpRequest signedRequest = signer.sign(request, credential);
HttpResponse response = signedRequest.execute();
String result = response.parseAsString();
System.out.println("result::" + result);
}
最佳答案
所以我终于能够做到了。我使用的这种方法是Akamai提供的快速清除方法。
代码示例:
public class AkamaiFastPurge {
private static final String HTTPS = "https";
public static void main(String... s) throws URISyntaxException, IOException, RequestSigningException {
ClientCredential credential = ClientCredential.builder()
.accessToken("Your-access-token")
.clientToken("Your-client-token")
.clientSecret("Your-client-secret")
.host("Your-host")
.build();
ArrayList arrayList = new ArrayList<String>();
// You can add multiple urls.
arrayList.add("*****-Actual-url-you-want-to-purge*****");
HttpResponse response = invalidateUrls(credential, arrayList, "production");
System.out.println(response.getStatusCode());
System.out.println(response.getStatusMessage());
}
public static HttpResponse invalidateUrls(ClientCredential clientCredential, List<String> urls, String network) {
HttpTransport httpTransport = new ApacheHttpTransport();
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
HttpRequest request = null;
try {
// This is fast purge approach
URI uri = new URI(HTTPS, "api.ccu.akamai.com", "/ccu/v3/invalidate/url/" + network, null, null);
String requestBody = getStringRequestBody(urls);
request = requestFactory.buildPostRequest(new GenericUrl(uri), ByteArrayContent.fromString("application/json", requestBody));
GoogleHttpClientEdgeGridRequestSigner requestSigner = new GoogleHttpClientEdgeGridRequestSigner(clientCredential);
requestSigner.sign(request);
return request.execute();
} catch (IOException e) {
// log.error("IOException in Akamai Utility", e);
} catch (RequestSigningException e) {
// log.error("RequestSigningException in Akamai Utility", e);
} catch (URISyntaxException e) {
// log.error("UriSyntaxException in Akamai Utility", e);
}
return null;
}
public static String getStringRequestBody(List<String> urls) {
Map<String, List<String>> akamaiRequestMap = Maps.newHashMap();
akamaiRequestMap.put("objects", urls);
return new Gson().toJson(akamaiRequestMap);
}
}
我使用的依赖项:
<dependency>
<groupId>com.akamai.edgegrid</groupId>
<artifactId>edgegrid-signer-google-http-client</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
关于java - 通过java代码清除akamai中缓存的url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52192577/
有人在使用 Akamai 实现运行域级 cookie 时遇到过问题吗?该站点发布一个域级 cookie,其中包含其他应用程序使用的 2 个值。如果混合使用 Akamai,则永远不会生成 cookie。
Akamai 多久刷新一次缓存? 我们使用 Akamai 来缓存经常访问的文件。将文件上传和覆盖到 Akamai FTP 时,我看不到实时反射(reflect)的新文件。 有没有人有这方面的经验? 最
如果 Akamai 边缘服务器缓存了一个 url,它是否会与其他边缘服务器共享该内容,或者没有在本地缓存内容的边缘服务器是否会返回源以获取内容? 我很想为此获得官方的 Akamai 文档,但当然会感谢
用例: 我正在使用 java 程序通过 CPCode 和 URL 进行清除。下面的代码用于连接和清除 Akamai。 credential = ClientCredential.builder().a
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 Improv
我正在尝试测试一些代码并查看它在使用 Akamai 进行缓存时的工作方式。任何人都可以推荐一个工具或插件,它可以让我模拟页面加载,就像 Akamai 缓存时一样? 最佳答案 大约一年前我使用了 Aka
我想使用 Akamai 来存储文件。我想知道Akamai是否提供任何API(例如网络服务)供我们上传、下载、列出文件?如果有人可以为新手提供一些文件,我们将不胜感激。 另一个问题是,如果我将视频文件上
是否可以使用 azure 门户将 akamai 的多个 IP 在应用程序网关列入白名单。 最佳答案 根据您使用的 Akamai 应用程序,您应该查看 Origin IP ACL最近添加到属性(prop
传统上,我会通过安装名为 akamaiheaders.xpi 的 Firefox 扩展来检查 Akamai header 。不幸的是,我认为支持此功能的最后一个版本是 Firefox 3。 据我了解,
我正在开发一个 android 应用程序,其中包含一个视频 View ,可以播放来自 akamai CDN 的 hls 流。问题是流式 url 具有使用 Akamai API 生成的 token 身份
我正在尝试使用 ffmpeg 将视频从我的网络摄像头流式传输到 AkamaiHD 服务(就像它在 Flash Media Live Encoder 中实现一样) ffmpeg -f dshow
我需要将位于 Akamai HD 服务器上的视频的 Flash 播放器转换为 HTML 5 版本。但是我过去没有与 Akamai 合作,所以我在 Akamai 中完全是新手,开发时间有限。 视频已经是
遇到一个让我抓狂的问题。在 AEM (6.0 SP3) 中实现 Amakai Edgegrid 身份验证,它会阻止我的主要服务包启动,因为它不是 OSGi 包。 与 this issue 中指出的问题
我有一个翻译成 18 种语言的网站(有 18 个翻译域)。它还具有基于语言的动态内容,即不同的产品,其中一些仅以特定语言提供。虽然有一个语言选择器,人们可以使用它来切换语言,从而切换站点,但人们找到他
我有一个静态网站,目前托管在 apache 服务器中。我有一个 akamai 服务器,它将对我站点的请求路由到这些服务器。我想将我的静态网站移动到 Amazon S3,以避免在我的服务器中托管这些静态
所以,我想为我的 css 和 js 文件添加版本控制。我想要执行此操作的方法是将查询字符串附加到 Assets 路径的末尾,这样 /foo/bar/baz.css 成为 /foo/bar/baz.cs
这是一个边缘用例,但我想将一些 JavaScript 注入(inject)到页面中,而无需在后端进行代码更改。所以我想知道我是否可以为 Akamai 的特定路由设置规则,该规则会注入(inject)或
我正在使用 HTTPS 在 Akamai 上设置 www.example.com。我将 www.example.com 指向 Akamai Edge 主机名,并将 www.example.com 域添
我在 Opendota API 中获取了一些数据,我注意到他们的 Steam 用户图像托管在其他地方,即位于 akamai 服务器上。 这是我在html中打印时的路径 https://steamcdn
如果指定的 cookie 存在(即如果用户登录特定页面),我希望 Akamai 不缓存某些 URL。无论如何我们可以使用 Akamai 做些什么? 最佳答案 好消息是,我过去曾为 Top Gear 网
我是一名优秀的程序员,十分优秀!