Purge and prefetch

更新时间:
复制 MD 格式

When your origin server content is updated or you need to remove non-compliant resources, you must purge the cache on Content Delivery Network (CDN) points of presence (POPs). This ensures users access the latest content. Before an event or new content goes live, prefetching resources to CDN POPs can significantly improve first-visit speed for users and reduce the load on your origin server. This topic describes how to use the cache purge and resource prefetch features of ApsaraVideo VOD.

How it works

Resource purge

A purge operation sends a cache invalidation command to CDN POPs instead of directly deleting files. When a POP receives the command, it marks the matching cached resources as "invalid" or "expired." When a user next requests the resource, the POP detects the invalid cache, fetches the latest version from the origin server, and serves it to the user while re-caching it.

Use cases

  1. Update and release content: After updating resources on your origin server, purge them to ensure users receive the latest version. The content is then re-cached on the POPs.

  2. Remove non-compliant content: If your origin server contains non-compliant content, it may remain in the CDN cache even after you delete the source file. Use the URL purge feature to clear the resource from the cache.

Resource prefetch

A prefetch operation instructs CDN POPs to proactively fetch and cache resources from your origin server based on a URL list you provide. This is a "pull" model, not a "push" from the origin server. Prefetching improves initial loading speeds, reduces origin fetch pressure during high-traffic events, and helps protect your origin server.

Use cases

  1. Onboard to Alibaba Cloud CDN: When adding a new domain to Alibaba Cloud CDN, prefetch its popular static resources to the POPs. This ensures initial user requests are served directly from the cache, preventing slow load times and improving the user experience.

  2. Support promotional campaigns: For large-scale campaigns, prefetch the static resources of the event pages to the POPs in advance. When the campaign starts, all user requests for these static resources are served directly from the POPs, ensuring fast page loads.

  3. Publish installation packages or large files: Before releasing new software, installation packages, or other large files, prefetch them to the POPs. After launch, the massive volume of download requests will be served directly from the CDN cache. This improves download speeds, reduces origin server load, and enhances the user experience.

Prerequisites

  • Timing: Purge and prefetch tasks generate back-to-origin traffic. You can run large-scale purge or prefetch tasks during off-peak hours.

  • URL format: If a URL that you submit contains non-ASCII characters, such as Chinese characters or spaces, you must first perform percent-encoding in UTF-8.

  • Shared cache: If a domain name is configured with a shared cache, submitting a purge task using the primary domain name or any associated domain name invalidates the cache for all associated domain names.

Procedure

Purge resources

  1. Log on to the ApsaraVideo VOD console.

  2. In the left-side navigation pane, choose Configuration Management > CDN Configuration > Refresh and Prefetch.

  3. On the Purge Cache tab, set Operation Type to Purge.

  4. Select a refresh method based on your requirements and submit the task.

    Refresh Method

    Description

    URL

    Purpose: Purge the cache for one or more specific files.

    Operation: In the URL text box, enter the full URLs, including http:// or https://. Enter one URL per line. Example: https://www.example.com/static/image.jpg.

    Folder

    Purpose: Purge the cache for all files and subdirectories in a CDN directory.

    Operation: Enter the complete directory URL, and make sure it ends with /. For example: https://www.example.com/static/.

    Note: This is an update-based purge. To force purge the entire directory, use Refresh Cache and set Force=true.

  5. Click Submit. The system starts to run the purge task.

    Note
    • You cannot abort a purge task after it is submitted.

    • A purge task typically takes 5 to 6 minutes to take effect across the entire network. If the time-to-live (TTL) of the cache is shorter than this duration, you do not need to manually purge the cache.

Prefetch resources

  1. Log on to the ApsaraVideo VOD console.

  2. In the left-side navigation pane, choose Configuration Management > CDN Configuration > Refresh and Prefetch.

  3. On the Purge Cache tab, set Operation Type to Prefetch.

  4. In the URL text box, enter the full URLs of the files that you want to prefetch. Enter one URL per line. You cannot prefetch directories. Example: https://www.example.com/install/package.zip.

  5. Click Submit. The system starts to run the prefetch task.

    Note
    • You cannot abort a prefetch task after it is submitted.

    • The time required to complete a prefetch task depends on the file size, number of files, and origin server performance. It typically takes 5 to 30 minutes.

Validation Results

  • Manual query

    On the Operation Record tab, you can view the details and progress of purge or prefetch tasks. A progress of 100% indicates that the task is complete. If you purge or prefetch many resources, the task may take longer to complete. Wait for the task to finish.

  • API query

    You can call the GetMediaRefreshJobs operation to check the status of a purge or prefetch task.

  • Command line validation

    Run the curl -I <resource_URL> command. The output is similar to the following:

    image

    If the X-Cache header exists:

    • If X-Cache is HIT, the request hit the cache and the prefetch was successful.

    • If X-Cache is MISS, the request missed the cache. This indicates that the prefetch task is incomplete or has failed. Prefetch the resource again.

    If the X-Cache header does not exist:

    If the X-Cache header is not present, the resource has not been added to CDN. Follow the instructions in Add a domain name to configure the domain name for the URL, and then prefetch the resource.

Limits

Operation type

Method

Quota limit

refresh

URL purge

Each account can submit up to 2,000 entries per day, with a maximum of 1,000 entries per request.

directory refresh

Each account is limited to 100 requests per day and 100 items per request.

Prefetch

URL prefetch

You can submit up to 500 items per account per day and up to 100 items per request.

Billing

The purge and prefetch features are free of charge.

However, both operations trigger CDN edge POPs to pull resources from the origin server. This generates costs for back-to-origin traffic and origin requests. The billing standards depend on the type of origin server you use:

  • If the origin server is an ApsaraVideo VOD bucket, you are charged for outbound traffic from storage.

  • If the origin server is Alibaba Cloud Object Storage Service (OSS), you are charged for traffic and requests based on the OSS billing rules.

Important

Large-scale purge or prefetch operations, especially within a short period, may increase back-to-origin costs. Evaluate the potential cost impact before you perform these operations.

Related API operations

FAQ