跳转至

刷新缓存

1. 接口描述

接口请求路径:POST /prod-api/cdn/layer7/cache/refreshCache

refreshCache 用于发起 URL 预热、URL 刷新或目录刷新任务。单次最多 20 条 URL。

Token 获取方式见 密钥鉴权

2. 输入参数

以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数

参数名称 必选 类型 描述
action Integer 操作类型。取值:1(URL 预热)、2(URL 刷新)、3(目录刷新)
示例值:2
urlList Array of String 待刷新/预热的 URL 列表,需携带 httphttps 完整路径,单次最多 20 条
示例值:["http://user.qqapex.com/"]

3. 示例

示例1 URL 刷新

输入示例

{
  "action": 2,
  "urlList": ["http://user.qqapex.com/"]
}

代码调用

请将 {登录域名}token 替换为实际值。

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class RefreshCacheTest {

    public static void main(String[] args) throws Exception {
        String url = "https://{登录域名}/prod-api/cdn/layer7/cache/refreshCache";
        String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";

        String requestBody = "{"
                + "\"action\":2,"
                + "\"urlList\":[\"http://user.qqapex.com/\"]"
                + "}";

        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            HttpPost httpPost = new HttpPost(url);
            httpPost.setHeader("Authorization", "Bearer " + token);
            httpPost.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));

            try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
                int statusCode = response.getStatusLine().getStatusCode();
                String body = EntityUtils.toString(response.getEntity(), "UTF-8");
                System.out.println("Status Code: " + statusCode);
                System.out.println("Body: " + body);
            }
        }
    }
}
package main

import (
    "bytes"
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://{登录域名}/prod-api/cdn/layer7/cache/refreshCache"
    token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"

    requestBody := []byte(`{
  "action": 2,
  "urlList": ["http://user.qqapex.com/"]
}`)

    req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(requestBody))
    if err != nil {
        panic(err)
    }
    req.Header.Set("Authorization", "Bearer "+token)
    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }
    fmt.Println("Status Code:", resp.StatusCode)
    fmt.Println("Body:", string(body))
}

输出示例

{
  "msg": "发起刷新任务成功,刷新完成时间大概需要1分钟",
  "code": 200
}

4. 输出参数

参数名称 类型 描述
code Integer 状态码。示例值:200
msg String 提示信息。示例值:发起刷新任务成功,刷新完成时间大概需要1分钟

5. 错误码

HTTP 状态码 / 业务提示 描述
200 成功
401 未鉴权或 Token 无效
403 无权限
请输入需要刷新的URL urlList 为空或未传
一次最多只能刷新20条URL urlList 超过 20 条
发起刷新任务失败 任务创建失败