Cache rule configuration

You can use the API to configure cache rules for directories, file names, and full paths.

  • Directory-based configuration: Directories must begin with a forward slash (/) (for example, /pic, /doc, or /htdoc/data). The back end matches all files within the designated directory, including subdirectories.

  • File extension-based configuration: Common file extensions, such as .jpg, .png, .gif, .txt, .m4v, or .mp3. The back end matches the specified file suffixes within all folders.

  • Full path-based configuration: Used to specify a single file, and must start with a forward slash (/) (for example, /sites/doc/example.doc). If the path that you enter is "/", it will match the home page.

    Note

    The character strings that you enter when you configure rules must not include any of the following special characters: {, }, (, ), [, ], ., ?, *, , ^, or $.

    A time value of 0 indicates that caching is disabled, and the no-cache rules are prioritized.  

Request

Method Request URI
PUT https://restapi.cdn.azure.cn/subscriptions/{subscriptionId}/endpoints/{endpointId}/cacherules?apiVersion=1.0

URI parameter

Parameter name Description
subscriptionId Subscription unique identifier
endpointId Target node unique identifier

Request header

Request header Description
x-azurecdn-request-date Required. Enter the current UTC request time in yyyy-MM-dd hh:mm:ss format.
Authorization Required. Refer to CDN API signing mechanism for authorization headers.
content-type Required. application/json

Request body

{
  "Rules": [
    {
      "Type": "Dir",
      "Items": [
        "/test1/",
        "/test2/"
      ],
      "TTL": 86400
    },
    {
      "Type": "Suffix",
      "Items": [
        "7z",
        "apk",
        "wdf",
        "cab"
      ],
      "TTL": 2592000
    },
    {
      "Type": "FullUri",
      "Items": [
        "/test1/test.xml",
        "/test2/test.txt"
      ],
      "TTL": 86400
    },
  ],
  "IgnoreCacheControl": false,
  "IgnoreCookie": false,
  "IgnoreQueryString": false
}
Parameter name Description
TTL Cache time, in seconds.
IgnoreCacheControl Indicates whether to ignore the cache-control header in the returned header and cache the request content.
IgnoreCookie Indicates whether to ignore the set-cookie header in the returned header and cache the request content.
IgnoreQueryString Indicates whether to ignore the query parameter and cache the request content.
Type Cache rule type
  • Suffix: Cache based on the file extension
  • Dir: Cache all files in the specified directory
  • FullUri: Cache files at a specific path

Response

A response comprises a status code, response headers, and a response body.

Status code

Status code Description
202 Indicates that the server has successfully accepted the request.
Other General response indicating that an error has occurred.

Response header

Response header Description
X-Correlation-Id The request's unique identifier, which is used to track request information.

Response body

JSON example for request succeeded:

{
  "Succeeded": true,
  "IsAsync": true,
  "AsyncInfo": {
    "TaskTrackId": "b520c544-ec34-4ac4-86f5-5394363919c3",
    "TaskStatus": "Processing"
  }
}
Parameter name Description
TaskTrackId The operation's unique identifier, which can be used to query progress.
TaskStatus Task status
  • NotSet: State not set
  • Processing: Currently processing
  • Succeeded: Succeeded
  • Failed: Failed

JSON example for request failed:

{
  "Succeeded": false,
  "ErrorInfo": {
    "Type": "MissingAuthorizationHeader",
    "Message": "Missing authorization header."
  }
}
Parameter name Description
Type Error type
  • CredentialInvalid: Invalid credentials
  • ParameterMissing: Parameter missing
  • ParameterInvalid: Invalid parameter
  • MissingAuthorizationHeader: Authorization header missing
  • InvalidRequestDateHeader: Invalid request date header
  • MissingRequestDateHeader: Missing request date header
  • AuthorizationHeaderExpired: Authorization header expired
  • InvalidAuthorizationHeader: Invalid authorization header
  • ApiKeyNotFound: API key not found
  • InvalidApiKey: Invalid API key
  • WrongSignature: Wrong signature
  • SubscriptionNotFound: Subscription does not exist
  • EndpointDoesNotBelongToSubscription: Endpoint does not belong to subscription
  • EndpointNotInActiveState: Endpoint not in active state
  • EndpointNotFound: Endpoint does not exist
  • MaliciousItemPathDetected: Malicious item path detected
  • PermissionDenied: Insufficient permissions
  • RequestThrottled: Request throttled

Message Error information