Overview
Menu

CreatePurgeTask

1. API Description

Domain name for API request: teo.tencentcloudapi.com.

When there are resources updated on the origin with the TTL remaining valid, users cannot access the latest resources. In this case, you can purge the cache using this API. There are two methods:

  • Delete: This method deletes the node cache without verification and retrieves the latest resources from the origin when receiving a request.
  • Invalidate: This method marks the node cache as invalid and sends a request with the If-None-Match and If-Modified-Since headers to the origin. If the origin responses with 200, the latest resources are retrieved to be cached on the node. If a 304 response is returned, the latest resources are not cached on the node.
  • For more details, see [Cache Purge](https://intl.cloud.tencent.com/document/product/1552/70759?from_cn_redirect=1).

    A maximum of 20 requests can be initiated per second for this API.

    We recommend you to use API Explorer
    Try it
    API Explorer provides a range of capabilities, including online call, signature authentication, SDK code generation, and API quick search. It enables you to view the request, response, and auto-generated examples.

    2. Input Parameters

    The following request parameter list only provides API request parameters and some common parameters. For the complete common parameter list, see Common Request Parameters.

    Parameter NameRequiredTypeDescription
    ActionYesStringCommon Params. The value used for this API: CreatePurgeTask.
    VersionYesStringCommon Params. The value used for this API: 2022-09-01.
    RegionNoStringCommon Params. This parameter is not required.
    ZoneIdYesStringID of the site.
    TypeYesStringType of cache purging. Values:
  • purge_url: Purge by the URL
  • purge_prefix: Purge by the directory
  • purge_host: Purge by the hostname
  • purge_all: Purge all caches
  • purge_cache_tag: Purge by the cache-tag
  • For more details, see Cache Purge.
    MethodNoStringNode cache purge method, valid for directory, hostname, and all cache refreshes. Valid values:
  • invalidate: Refreshes only resources that were updated under the directory;
  • delete: Refreshes all node resources, regardless of whether they were updated.
  • Default value: invalidate.
    Targets.NNoArray of StringList of resources for which cache is to be purged. Each element format depends on the cache purge type and you can refer to the API examples for details.
  • The number of tasks that can be submitted at a time is limited by the quota of a billing package. For details, see [Billing Overview] (https://intl.cloud.tencent.com/document/product/1552/77380?from_cn_redirect=1).
  • 3. Output Parameters

    Parameter NameTypeDescription
    JobIdStringID of the task.
    FailedListArray of FailReasonList of failed tasks and reasons.
    Note: This field may return null, indicating that no valid values can be obtained.
    RequestIdStringThe unique request ID, generated by the server, will be returned for every request (if the request fails to reach the server for other reasons, the request will not obtain a RequestId). RequestId is required for locating a problem.

    4. Example

    Example1 Purging by the URL

    By using Delete method, resources under a URL that matches the specified hostname are removed.
    This example shows you how to purge resources in the directory /a.txt under the site domain www.example.com.

    Input Example

    POST / HTTP/1.1
    Host: teo.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreatePurgeTask
    <Common request parameters>
    
    {
        "Targets": [
            "http://www.example.com/a.txt"
        ],
        "Type": "purge_url",
        "ZoneId": "zone-ajj243dwrew"
    }
    

    Output Example

    {
        "Response": {
            "JobId": "20ga521cpwch",
            "FailedList": [],
            "RequestId": "3c140219-cfe9-470e-b241-907877d6fb03"
        }
    }
    

    Example2 Purging by the hostname

    By using Invalidate method, resources under a domain name that matches the specified hostname are marked as invalid.
    This example shows you how to purge resources changed under the site domain www.example.com.

  • Note: Domain names cannot include wildcards (*).
  • Input Example

    POST / HTTP/1.1
    Host: teo.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreatePurgeTask
    <Common request parameters>
    
    {
        "Targets": [
            "www.example.com"
        ],
        "Type": "purge_host",
        "ZoneId": "zone-ajj243dwrew"
    }
    

    Output Example

    {
        "Response": {
            "JobId": "20ga521cpwcs",
            "FailedList": [],
            "RequestId": "3c140219-cfe9-470e-b241-907877d6fb03"
        }
    }
    

    Example3 Purging by the Cache-Tag

    By using Invalidate method, resources under a site are associated with tags in the HTTP response header Cache-Tag and marked as invalid.
    This example shows you how to purge resources that contain tag1, tag2 and tag3 and have changed under the site example.com.

    Input Example

    POST / HTTP/1.1
    Host: teo.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreatePurgeTask
    <Common request parameters>
    
    {
        "Targets": [
            "tag1",
            "tag2",
            "tag3"
        ],
        "Type": "purge_cache_tag",
        "ZoneId": "zone-ajj243dwrew"
    }
    

    Output Example

    {
        "Response": {
            "JobId": "20ga521cpwcs",
            "FailedList": [],
            "RequestId": "3c140219-cfe9-470e-b241-907877d6fb03"
        }
    }
    

    Example4 Purging all caches under a site

    By using Invalidate method, all cached resources under a site are marked as invalid.
    This example shows you how to purge all cached resources changed under the site example.com.

    Input Example

    POST / HTTP/1.1
    Host: teo.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreatePurgeTask
    <Common request parameters>
    
    {
        "Type": "purge_all",
        "ZoneId": "zone-ajj243dwrew"
    }
    

    Output Example

    {
        "Response": {
            "JobId": "20ga521cpwcs",
            "FailedList": [],
            "RequestId": "3c140219-cfe9-470e-b241-907877d6fb03"
        }
    }
    

    Example5 Purging by the directory – Deleting resources in the directory

    To purge all resources under a directory, pass delete into the Method field.
    This example shows you how to purge all resources in the /test directory under www.example.com.

    Input Example

    POST / HTTP/1.1
    Host: teo.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreatePurgeTask
    <Common request parameters>
    
    {
        "Targets": [
            "http://www.example.com/test/"
        ],
        "Type": "purge_prefix",
        "Method": "delete",
        "ZoneId": "zone-ajj243dwrew"
    }
    

    Output Example

    {
        "Response": {
            "JobId": "20ga521cpwck",
            "FailedList": [],
            "RequestId": "3c140219-cfe9-470e-b241-907877d6fb03"
        }
    }
    

    Example6 Only purging resources updated in the directory

    To purge the resources updated under a directory, pass invalidate into the Method field.
    This example shows you how to purge resources changed in the directory /test under the site domain www.example.com.

    Input Example

    POST / HTTP/1.1
    Host: teo.tencentcloudapi.com
    Content-Type: application/json
    X-TC-Action: CreatePurgeTask
    <Common request parameters>
    
    {
        "Targets": [
            "http://www.example.com/test/"
        ],
        "Type": "purge_prefix",
        "Method": "invalidate",
        "ZoneId": "zone-ajj243dwrew"
    }
    

    Output Example

    {
        "Response": {
            "JobId": "20ga521cpwcj",
            "FailedList": [],
            "RequestId": "3c140219-cfe9-470e-b241-907877d6fb03"
        }
    }
    

    5. Developer Resources

    SDK

    TencentCloud API 3.0 integrates SDKs that support various programming languages to make it easier for you to call APIs.

    Command Line Interface

    6. Error Code

    The following only lists the error codes related to the API business logic. For other error codes, see Common Error Codes.

    Error CodeDescription
    InternalError.BackendErrorServer error.
    InternalError.DomainConfigFailed to get configuration
    InternalError.ProxyServerAn unknown error occurred in the backend server.
    InternalError.QuotaSystemServer error.
    InvalidParameter.DomainNotFoundThe domain name does not exist or is not belong to this account.
    InvalidParameter.ParameterErrorParameter error: Invalid “End time”. The interval between the start and end time cannot exceed 7 days.
    InvalidParameter.TargetResource error
    InvalidParameter.TaskNotGeneratedFailed to create the task
    InvalidParameter.UploadUrlInvalid file upload link.
    LimitExceeded.BatchQuotaReached the upper limit of resource number
    LimitExceeded.DailyQuotaReached the daily upper limit of resource number
    LimitExceeded.PackNotAllowNot supported by the plan.
    UnauthorizedOperation.CamUnauthorizedCAM is not authorized.
    UnauthorizedOperation.NoPermissionThe sub-account is not authorized for the operation. Please get permissions first.
    UnauthorizedOperation.UnknownAn unknown error occurred in the backend server.