缓存管理
更新时间:2023-05-16
刷新缓存
public void purgeUrl(CdnClient client) {
String domain = "my.test.com";
PurgeRequest request = new PurgeRequest()
.addTask(new PurgeTask().withUrl("http://" + domain + "/url"))
.addTask(new PurgeTask().withDirectory("http://" + domain + "/directory/"));
PurgeResponse purgeResponse = client.purge(request);
System.out.println(purgeResponse);
// 根据任务id查询刷新结果
GetPurgeStatusResponse purgeStatusResponse = client.getPurgeStatus(
new GetPurgeStatusRequest().withId(purgeResponse.getId()));
System.out.println(purgeStatusResponse);
}
查询刷新状态
public void testGetPurgeStatus(CdnClient client) {
String id = "eJwNyMERABAMBMCKMnPicH5aiQz9l8A";
GetPurgeStatusRequest request = new GetPurgeStatusRequest().withId(id);
GetPurgeStatusResponse response = cdnClient.getPurgeStatus(request);
System.out.println(response);
}
查询限额
public void getCacheQuota(CdnClient client) {
GetCacheQuotaResponse response = cdnClient.getCacheQuota();
System.out.println(response);
}
预热缓存
public void prefetchUrl(CdnClient client) {
String domain = "my.test.com";
// 用法1
PrefetchRequest request = new PrefetchRequest()
.addTask(new PrefetchTask().withUrl("http://" + domain + "/url"));
PrefetchResponse prefetchResponse = client.prefetch(request);
System.out.println(prefetchResponse);
// 用法2
PrefetchResponse prefetchResponse = client.prefetch("http://" + domain + "/url");
System.out.println(prefetchResponse);
}
查询预加载状态
public void testGetPrefetchStatus(CdnClient client) {
String id = "eJwNyMERABAMBMCKMnPicH5aiQz9l8A";
GetPrefetchStatusResponse response = cdnClient.getPrefetchStatus(
new GetPrefetchStatusRequest().withId(id));
System.out.println(response);
}