免责声明:本文档可能包含第三方产品信息,该信息仅供参考。阿里云对第三方产品的性能、可靠性以及操作可能带来的潜在影响,不做任何暗示或其他形式的承诺。
概述
本文主要介绍如何使用CDN的JAVA SDK刷新缓存。
详细信息
阿里云CDN为您提供了JAVA、Python、PHP、.Net等多种语言的SDK,详情请参见阿里云SDK中心。本文以JAVA SDK为例进行说明。
- 使用JAVA SDK时,请在pom.xml文件中添加如下代码,注意需要添加准确的SDK版本号,详情请参见阿里云SDK中心。
<!--添加阿里云core依赖和cdn依赖-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-cdn</artifactId>
<version>3.0.10</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.1.0</version>
</dependency> - 发起调用之前前,请先初始化IAcsClient实例,示例代码如下。
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
IAcsClient client = new DefaultAcsClient(profile); - 构造刷新请求,请参考如下完整的示例代码。
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.cdn.model.v20180510.*;
public class RefreshObjectCaches {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");
IAcsClient client = new DefaultAcsClient(profile);
RefreshObjectCachesRequest request = new RefreshObjectCachesRequest();
request.setObjectPath("example.aliyundoc.com/abc/1.png");
request.setObjectType("File");
try {
RefreshObjectCachesResponse response = client.getAcsResponse(request);
System.out.println(new Gson().toJson(response));
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
System.out.println("ErrCode:" + e.getErrCode());
System.out.println("ErrMsg:" + e.getErrMsg());
System.out.println("RequestId:" + e.getRequestId());
}
}
}
适用于
- CDN