跳到主要内容

Create Cache Control Rule

Create cache control rule for website acceleration.

Request

Request-Line

POST /waap/v1.0/services/{serviceId}/cacheControls HTTP/1.1

Request Parameters

Path Parameters

ParameterTypeRequiredDescription
serviceIdIntegerMandatoryService ID.

Body Parameters

ParameterTypeRequiredDescription
nameStringMandatoryRule name for access control.
matchUrlPathObjectMandatoryURL path matching configuration that determines which requests the rule applies to. See Match Url Path for details.
matchQueryStringObjectOptionalQuery-string matching configuration used to refine which requests the rule applies to. See Match Query String for details.
priorityIntegerOptionalPriority weight for the rule. Rules with a higher weight take precedence. The weight must be non-zero.
ttlLongOptionalTime-to-live (TTL) in seconds for content cached at the edge. If omitted, the origin cache TTL is used.
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.
neverCacheBooleanOptionalDo not cache the content even if the origin presents it as cacheable. Default is false.
varyMIMEsString[]OptionalConfigures so-called "vary for images" feature.Contains a list of mime types, preferred for objects matched by the rule. Supported values: image/webp, image/avif, image/jpeg, image/jpg, image/png
enabledBooleanOptionalFlag indicating whether the rule is active. Default is true.
Object: Match Url Path
ParameterTypeRequiredDescription
operatorStringMandatoryDefines how to match the field. Supported values:prefix,regex,equals,suffix.
patternsString[]MandatoryList of patterns to match what against. If any of the patterns matches then the match succeeds.
Object: Match Query String
ParameterTypeRequiredDescription
operatorStringMandatoryDefines how to match the field. Supported values:prefix,regex,equals,suffix.
patternsString[]MandatoryList of patterns to match what against. If any of the patterns matches then the match succeeds.

Response

Response Body

Property nameTypeRequiredDescription
ruleIdIntegerMandatoryRule ID number for access control.
priorityIntegerMandatoryPriority weight of access control rule.

Status Codes, Error Codes and Error Messages

Status CodeError CodeError Message
400Request.BadRequestBad request.
400ServiceId.InvalidServiceId is empty or invalid.
400Name.InvalidName is empty or invalid.
400Priority.InvalidPriority is empty or invalid.
400Ttl.InvalidTtl is empty or invalid.
400MatchUrlPath.operator.InvalidMatchUrlPath.operator is empty or invalid.
400MatchUrlPath.patterns.InvalidMatchUrlPath.patterns is empty or invalid.
400MatchQueryString.operator.InvalidMatchQueryString.operator is empty or invalid.
400CacheControl.OperationFailedThe cache control operation failed.
404ServiceId.NotFoundServiceId is not found.
409Priority.ExistPriority already exists.

Examples

Create Cache Control Rule

Request

POST /waap/v1.0/services/12345/cacheControls HTTP/1.1

{
"name": "test",
"matchUrlPath": {
"operator": "prefix",
"patterns": [
"/"
]
},
"matchQueryString": {
"operator": "prefix",
"patterns": [
"name1=1",
"name2=2"
]
},
"priority": 1000,
"ttl": 100,
"ignoreClientNoCache": true,
"ignoreOriginNoCache": false,
"ignoreQueryString": false,
"enableXCache": false,
"neverCache": false,
"varyMIMEs": [
"image/jpg"
],
"enabled": true
}

Successful Response Body

{
"ruleId": 261700,
"priority": 1023
}