tencent cloud

Feedback

CreatePurgeTask

Last updated: 2024-04-09 10:26:13

    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://www.tencentcloud.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 Name Required Type Description
    Action Yes String Common Params. The value used for this API: CreatePurgeTask.
    Version Yes String Common Params. The value used for this API: 2022-09-01.
    Region No String Common Params. This parameter is not required.
    ZoneId Yes String ID of the site.
    Type Yes String Type 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.
    Method No String Node 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.N No Array of String List 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://www.tencentcloud.com/document/product/1552/77380?from_cn_redirect=1).
  • 3. Output Parameters

    Parameter Name Type Description
    JobId String ID of the task.
    FailedList Array of FailReason List of failed tasks and reasons.
    Note: This field may return null, indicating that no valid values can be obtained.
    RequestId String The 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 Code Description
    InternalError.BackendError Server error.
    InternalError.DomainConfig Failed to get configuration
    InternalError.ProxyServer An unknown error occurred in the backend server.
    InternalError.QuotaSystem Server error.
    InvalidParameter.DomainNotFound The domain name does not exist or is not belong to this account.
    InvalidParameter.ParameterError Parameter error: Invalid “End time”. The interval between the start and end time cannot exceed 7 days.
    InvalidParameter.Target Resource error
    InvalidParameter.TaskNotGenerated Failed to create the task
    InvalidParameter.UploadUrl Invalid file upload link.
    LimitExceeded.BatchQuota Reached the upper limit of resource number
    LimitExceeded.DailyQuota Reached the daily upper limit of resource number
    LimitExceeded.PackNotAllow Not supported by the plan.
    UnauthorizedOperation.CamUnauthorized CAM is not authorized.
    UnauthorizedOperation.NoPermission The sub-account is not authorized for the operation. Please get permissions first.
    UnauthorizedOperation.Unknown An unknown error occurred in the backend server.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support