跳转至

查询缓存规则

1. 接口描述

接口请求路径:GET /prod-api/cdn/layer7/advance/describeCacheRules

describeCacheRules 用于查询指定域名下的缓存规则列表。

Token 获取方式见 密钥鉴权

2. 输入参数

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

参数名称 必选 类型 描述
domainId Integer Query 参数。域名 ID
示例值:205

3. 示例

示例1 查询缓存规则

输入示例

GET /prod-api/cdn/layer7/advance/describeCacheRules?domainId=205

代码调用

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

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class DescribeCacheRulesTest {

    public static void main(String[] args) throws Exception {
        String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";

        URIBuilder uriBuilder = new URIBuilder("https://{登录域名}/prod-api/cdn/layer7/advance/describeCacheRules");
        uriBuilder.addParameter("domainId", "205");

        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            HttpGet httpGet = new HttpGet(uriBuilder.build());
            httpGet.setHeader("Authorization", "Bearer " + token);

            try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
                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 (
    "fmt"
    "io"
    "net/http"
    "net/url"
)

func main() {
    token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"

    u, err := url.Parse("https://{登录域名}/prod-api/cdn/layer7/advance/describeCacheRules")
    if err != nil {
        panic(err)
    }
    q := u.Query()
    q.Set("domainId", "205")
    u.RawQuery = q.Encode()

    req, err := http.NewRequest(http.MethodGet, u.String(), nil)
    if err != nil {
        panic(err)
    }
    req.Header.Set("Authorization", "Bearer "+token)

    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": "操作成功",
  "code": 200,
  "data": {
    "total": 1,
    "row": [
      {
        "locationId": 258,
        "name": "png;jpg;jpeg;gif;ico;bmp",
        "type": "2",
        "json": "{\"cacheTimeUnit\":\"s\",\"cacheTime\":0}",
        "sort": 2
      }
    ]
  }
}

4. 输出参数

参数名称 类型 描述
code Integer 状态码。示例值:200
msg String 提示信息。示例值:操作成功
data Object 缓存规则列表数据
data.total Integer 规则总数。示例值:1
data.row [CacheRuleRowVO] 缓存规则列表

type 取值说明

type 含义
1 全部
2 文件类型
3 文件夹
4 全路径
5 首页

json 字段说明

json 为 JSON 字符串,解析后常见字段:

字段 类型 描述
cacheTime Integer 缓存时间。示例值:0
cacheTimeUnit String 缓存时间单位。取值:s(秒)、m(分钟)、h(小时)、d(天)
ignoreHeaders Array of String 忽略的响应头,如 ExpiresCache-ControlSet-CookieX-Accel-Expires

5. 错误码

HTTP 状态码 / 业务提示 描述
200 成功
401 未鉴权或 Token 无效
403 无权限

6. 数据模型

CacheRuleRowVO

缓存规则项。

参数名称 类型 描述
locationId Integer 规则 ID,更新缓存规则 编辑时必填。示例值:258
name String 规则内容。文件类型时多个后缀以分号分隔。示例值:png;jpg;jpeg;gif;ico;bmp
type String 规则类型。取值见上方 type 对照表。示例值:2
json String 缓存设置 JSON 字符串,字段见上方 json 说明。示例值:{"cacheTimeUnit":"s","cacheTime":0}
sort Integer 排序值,数值越小优先级越高。示例值:2