Help Center> Content Delivery Network> API Reference> Examples> Creating a Cache Refreshing or Preheating Task
Updated on 2024-05-16 GMT+08:00

Creating a Cache Refreshing or Preheating Task

Description

This section describes how to create a cache refreshing or preheating task using APIs. For details about how to call APIs, see Calling APIs.

Involved APIs

Procedure

  1. Obtain a user token and use it for authentication when calling the API for creating a cache preheating or refreshing task. For details, see Making an API Request.
    • To obtain the username and domain name, log in to the Huawei Cloud management console, point to the account name in the upper right corner, and choose My Credentials from the drop-down list.
    • Request URL: POST https://iam.myhuaweicloud.com/v3/auth/tokens
    • Request header: Content-Type: application/json
    • Request body:
      {
      	"auth": {
      	"identity": {
      		"methods": ["password"],
      		"password": {
      			"user": {
      				"name": "name",           --Username
      				"password": "password",       --Password
      				"domain": {
      					"name": "domainname"    --Name of the account to which the user belongs
      				}
      			}
      		}
      	},
      	"scope": {
      			"domain": {
      				"name": "domainname"    --Name of the account to which the user belongs
      		}
      		}
      	}
        }

    Information in the red box in the following figure indicates the obtained user token.

  2. Create a cache preheating task.
    1. Select the POST request method and enter the request URI.
      POST  https://cdn.myhuaweicloud.com/v1.0/cdn/content/preheating-tasks
    2. Add X-Auth-Token to the request header.
    3. Specify the following parameters in the request body:
      {
         "preheating_task": {
             "urls": [
                 "https://www.bxxx/1.txt",
                 "https://www.bxxx/2.txt"
             ]
         }
       }
    4. Example response:
      {
       "preheating_task": "7620240"
       }
    5. If the request fails, an error code and error information are returned. For details, see Error Codes.
  3. Create a cache refreshing task.
    1. Select the POST request method and enter the request URI.
      POST  https://cdn.myhuaweicloud.com/v1.0/cdn/content/refresh-tasks
    2. Add X-Auth-Token to the request header.
    3. Specify the following parameters in the request body:
      {
         "refresh_task": {
             "type": "file",
             "urls": [
                 "https://www.bxxx/1.txt",
                 "https://www.bxxx/2.txt"
             ]
          }
       }
    4. Example response:
      {
       "refresh_task": "7620242"
       }
    5. If the request fails, an error code and error information are returned. For details, see Error Codes.