Skip to main content

Create Cache Control

This API is used to create cache control for website acceleration service.

Request

Request-Line

POST /cdn/v1.0/services/{serviceId}/cacheControl HTTP/1.1

Request Parameters

Path Parameters

ParameterTypeRequiredDescription
serviceIdIntegerMandatoryservice id.

Body Parameters

ParameterTypeRequiredDescription
policyNameStringMandatoryPolicy name for cache control.
matchUrlPathObjectMandatoryURL path matching configuration that determines which requests the rule applies to. See Match Url Path for details.
priorityIntegerMandatoryPriority weight for the rule. Rules with a higher weight take precedence. The weight must be non-zero.
matchQueryStringObjectOptionalQuery-string matching configuration used to refine which requests the rule applies to. See Match Query String for details.
ttlLongOptionalThe cache TTL for contents to be cached on edge server in seconds.
refererAclObjectOptionalConfigure resource references by creating a domain list and selecting a configuration type (e.g.,whitelist,blacklist) to control whether a domain has permission to access the resource,thereby ensuring resource security. see Referer Acl for details
originAclObjectOptionalConfigure origins by creating a domain list and selecting a configuration type (e.g.,whitelist,blacklist) to control whether a domain has permission to access data from origin,thereby ensuring resource security. see Origin Acl for details
ignoreClientNoCacheBooleanOptionalTrue or false to ignore no-cache header(s) sent by the client. Default is false.
ignoreOriginNoCacheBooleanOptionalTrue or false to ignore no-cache header(s) sent by the origin server. Default is false.
ignoreQueryStringBooleanOptionalTrue or false to ignore any URL query string when caching contents. Default is false.
enableXCacheBooleanOptionalWhen 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. Default is false.
noCacheBooleanOptionalDo not cache the content even if the origin presents it as cacheable. Default is false.
autoGzipDisableBooleanMandatoryDisable automatic gzipping on the CDN side. Default is false.
responseHeadersArrayOptionalList of response header configuration. See Response Headers for details.
varyMIMEsString[]OptionalConfigures so-called "vary for images" feature.Contains a list of mime types, preferred for objects matched by the policy.
enabledBooleanOptionalFlag defining if policy is active or no. default is true.
Object: Match Url Path
ParameterTypeRequiredDescription
operatorStringMandatoryDefines how to match the field. Supported values:prefix,regex,equals,suffix.
patternsString[]MandatoryList of patterns matching the URL path string.
Object: Match Query String
ParameterTypeRequiredDescription
operatorStringMandatoryDefines how to match the field. Supported values:prefix,regex,equals,suffix.
patternsString[]MandatoryList of patterns matching the URL query string.
Object: Referer/Origin Acl
ParameterTypeRequiredDescription
aclTypeStringMandatoryTypes of blacklist and whitelist.
domainListString[]MandatoryList of domainName.
Object: Response Headers
ParameterTypeRequiredDescription
nameStringMandatoryResponse Header Name.
operationTypeStringMandatoryOperation type of response header policy, could be "add" or "replace" or "delete"
valueStringOptionalResponse Header Value.

Response

Response Body

ParameterTypeDescription
policyIdIntegerPolicy ID number for cache control.
policyNameStringPolicy name for cache control.
matchUrlPathObjectURL path matching configuration that determines which requests the rule applies to. See Match Url Path for details.
priorityIntegerPriority weight for the rule. Rules with a higher weight take precedence. The weight must be non-zero.
ignoreClientNoCacheBooleanTrue or false to ignore no-cache header(s) sent by the client. Default is false.
ignoreOriginNoCacheBooleanTrue or false to ignore no-cache header(s) sent by the origin server. Default is false.
ignoreQueryStringBooleanTrue or false to ignore any URL query string when caching contents. Default is false.
enableXCacheBooleanWhen 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. Default is false.
noCacheBooleanDo not cache the content even if the origin presents it as cacheable. Default is false.
autoGzipDisableBooleanDisable automatic gzipping on the CDN side. Default is false.
responseHeadersArrayList of response header configuration. See Response Headers for details.
refererAclObjectConfigure resource references by creating a domain list and selecting a configuration type (e.g.,whitelist,blacklist) to control whether a domain has permission to access the resource,thereby ensuring resource security. see Referer Acl for details
originAclObjectConfigure origins by creating a domain list and selecting a configuration type (e.g.,whitelist,blacklist) to control whether a domain has permission to access data from origin,thereby ensuring resource security. see Origin Acl for details
ttlLongThe cache TTL for contents to be cached on edge server in seconds.
matchQueryStringObjectQuery-string matching configuration used to refine which requests the rule applies to. See Match Query String for details.
varyMIMEsString[]Configures so-called "vary for images" feature.Contains a list of mime types, preferred for objects matched by the policy.
enabledBooleanFlag defining if policy is active or no. default is true.

Status Codes, Error Codes and Error Messages

Status CodeError CodeError Message
400Request.BadRequestBad request.
400InvalidCustomer.IdEmptyCustomer id can be empty or invalid.
400InvalidService.IdIncorrectService id is empty or invalid.
400ServiceId.IdPermissionServiceId can not be found or unknown.
400Invalid.PolicyNamePolicy name is required.
400InvalidPolicy.MatchURLIncorrectThe matchUrlPath can not be empty.
400InvalidPolicy.OperatorOperator must be one of the following: prefix,regex,equals or suffix.
400InvalidPolicy.PatternsPatterns cannot be empty or invalid.
400InvalidPolicy.RefererAclInvalid AclType, must be in 'whitelist' or 'blacklist'.
400InvalidPolicy.AclDomainListThe AclDomainList array and every element in it must not be empty.
400InvalidPolicy.AclDomainTypeThe AclDomainList cannot be start with '-'
400InvalidPolicy.RefererAclInvalid AclType, must be in 'whitelist' or 'blacklist'.
400InvalidPolicy.PriorityPriority is required.
400InvalidService.VaryMiMEVaryMiME cannot be empty.
400InvalidPolicy.ResponseHeaderResponse header cannot be empty or invalid.

Examples

Create Cache Control

Request

POST /cdn/v1.0/services/228657/cacheControl HTTP/1.1

{
"policyName":"cacheInfo",
"matchUrlPath":{
"operator":"prefix",
"patterns":["/"]
},
"matchQueryString":{
"operator":"prefix",
"patterns":["/"]
},
"varyMIMEs": ["image/webp","image/avif"],
"priority":222,
"ttl":3600,
"refererAcl":{
"aclType":"whitelist",
"domainList":["www.1.com","example2.com"]
},
"originAcl":{
"aclType":"whitelist",
"domainList":["www.1.com"]
},
"ignoreClientNoCache":false,
"ignoreOriginNoCache":false,
"ignoreQueryString":true,
"enableXCache":true,
"noCache":false,
"autoGzipDisable":false,
"responseHeaders":[{
"name": "Content-Type",
"operationType": "add",
"value": "application/json"
}]
}

Successful Response Body

{
"policyId": 262021,
"policyName": "cacheInfo",
"ttl": 3600,
"refererAcl": {
"aclType": "whitelist",
"domainList": [
"www.1.com",
"example2.com"
]
},
"originAcl": {
"aclType": "whitelist",
"domainList": [
"www.1.com"
]
},
"ignoreClientNoCache": false,
"ignoreOriginNoCache": false,
"ignoreQueryString": true,
"enableXCache": true,
"noCache": false,
"autoGzipDisable": false,
"responseHeaders": [
{
"name": "Content-Type",
"value": "application/json",
"operationType": "Add"
}
],
"matchUrlPath": {
"operator": "prefix",
"patterns": [
"/"
]
},
"matchQueryString": {
"operator": "prefix",
"patterns": [
"/"
]
},
"varyMIMEs": [
"image/webp",
"image/avif"
],
"priority": 222,
"enabled": true
}