Create Cache Control V3
This API is used to create cache control for website acceleration or file download service.
1. Request Definition
- API URL
https://cdn-api.swiftfederation.com/v3.0/services/{serviceId}/cache_controls
- Request Method
POST
- Request Header
Refer to HTTP Request Headers
- Request Body
Request Body Data Format: JSON
Field | Required | Type | Description |
---|---|---|---|
name | Mandatory | string | Policy name for access control. |
matchUrlPath | Mandatory | PolicyMatchVO | URL path configuration. |
matchQueryString | Optional | PolicyMatchVO | Query string configuration. |
priority | Optional | int | Priority weight of access control policy. policy with bigger weight will have higher priority, weight value can not be zero. |
ttl | Optional | long | The cache TTL for contents to be cached on edge server in seconds. |
allowedReferrers | Optional | string | Comma-separated list of domain suffixes. If the Referer header of a client request does not match any of the suffixes in the list then the request is blocked with an HTTP 403 Permission Denied response. Suffixes match any domain name with the same ending, for example "example.com" will match both "www.example.com" and "subdomain.example.com". and if the domain suffixes start with '-', e.g. "-www.example.com", only block the domain suffixes as blacklist and allow others. |
allowedOrigins | Optional | string | Comma-separated list of domain suffixes. If the Origin header of a client request does not match any of the suffixes in the list then the request is blocked with an HTTP 403 Permission Denied response. Suffixes match any domain name with the same ending, for example "example.com" will match both "www.example.com" and "subdomain.example.com". and if the domain suffixes start with '-', e.g. "-www.example.com", only block the domain suffixes as blacklist and allow others. |
ignoreClientNoCache | Optional | boolean | True or false to ignore no-cache header(s) sent by the client. |
ignoreOriginNoCache | Optional | boolean | True or false to ignore no-cache header(s) sent by the origin server. |
ignoreQueryString | Optional | boolean | True or false to ignore any URL query string when caching contents. |
enableXCache | Optional | boolean | When enabled all responses from the edge have X-Cache header with values like "HIT from da01.xy01.swiftserve.com", showing whether the response was served from the cache (at least partially) or not. |
neverCache | Optional | boolean | Do not cache the content even if the origin presents it as cacheable. |
responseHeaders | Optional | ResponseHeader[] | List of response header configuration. |
varyMIMEs | Optional | string[] | Configures so-called "vary for images" feature.Contains a list of mime types, preferred for objects matched by the policy. |
enabled | Optional | boolean | Flag defining if policy is active or no. default: true. |
ResponseHeader Definition | |||
name | Mandatory | string | Response Header Name. |
value | Optional | string | Response Header Value. |
operationType | Mandatory | string | Operation type of response header policy, could be "add" or "replace" or "delete" |
PolicyMatchVO Definition | |||
operator | Mandatory | string | Defines how to match the field. Supported values:prefix,regex,equals,suffix. |
patterns | Mandatory | string[] | List of patterns to match what against. If any of the patterns matches then the match succeeds. |
- Request Body Example
{
"allowedOrigins": "",
"allowedReferrers": "",
"enableXCache": false,
"hostHeader": "",
"ignoreClientNoCache": false,
"ignoreOriginNoCache": false,
"ignoreQueryString": false,
"name": "149",
"neverCache": false,
"originSniOverride": "",
"priority": null,
"responseHeaders": [],
"ttl": 86400,
"matchUrlPath": {"operator":"prefix","patterns":["/"]},
"matchQueryString": {"operator":"prefix","patterns":["name1=1","name2=2"]},
"varyMIMEs":["image/webp","image/avif","image/jpeg"]
}
2. Response Definition
- Response Header
Refer to HTTP Response Headers
- Response Body
Field | Type | Description | |
---|---|---|---|
id | int | Policy ID number for access control. | |
name | string | Policy name for access control. | |
matchUrlPath | PolicyMatchVO | URL path match rule. | |
matchQueryString | PolicyMatchVO | Query string match rule. | |
priority | int | Priority weight of access control policy. policy with bigger weight will have higher priority, weight value can not be zero. | |
ttl | long | The cache TTL for contents to be cached on edge server in seconds. | |
allowedReferrers | string | Comma-separated list of domain suffixes. If the Referer header of a client request does not match any of the suffixes in the list then the request is blocked with an HTTP 403 Permission Denied response. Suffixes match any domain name with the same ending, for example "example.com" will match both "www.example.com" and "subdomain.example.com". | |
ignoreClientNoCache | boolean | True or false to ignore no-cache header(s) sent by the client. | |
ignoreOriginNoCache | boolean | True or false to ignore no-cache header(s) sent by the origin server. | |
ignoreQueryString | boolean | True or false to ignore any URL query string when caching contents. | |
enableXCache | boolean | When enabled all responses from the edge have X-Cache header with values like "HIT from da01.xy01.swiftserve.com", showing whether the response was served from the cache (at least partially) or not. | |
neverCache | boolean | Do not cache the content even if the origin presents it as cacheable. | |
responseHeaders | ResponseHeader[] | List of response header configuration. | |
varyMIMEs | string[] | Configures so-called "vary for images" feature.Contains a list of mime types, preferred for objects matched by the policy. | |
enabled | boolean | Flag defining if policy is active or no. | |
ResponseHeader Definition | |||
operationType | string | Operation type of response header policy, could be "add" or "replace" or "delete" | |
name | string | Response Header Name. | |
value | Optional | string | Response Header Value. ignored when Operation type is "delete" |
PolicyMatchVO Definition | |||
operator | string | Defines how to match the field. Supported values:prefix,regex,equals,suffix. | |
patterns | string[] | List of patterns to match what against. If any of the patterns matches then the match succeeds. |
- Response Body Example
{
"name": "149",
"matchUrlPath": {"operator":"prefix","patterns":["/"]},
"matchQueryString": {"operator":"prefix","patterns":["name1=1","name2=2"]},
"priority": 5647,
"id": 258875,
"ttl": 86400,
"ignoreClientNoCache": false,
"ignoreOriginNoCache": false,
"ignoreQueryString": false,
"enableXCache": false,
"neverCache": false,
"autoGzipDisable": false,
"responseHeaders": [],
"varyMIMEs":["image/webp","image/avif","image/jpeg"]
}