Refresh and prefetch resources

Updated at:

Purging instantly removes specified content from the DCDN cache, forcing a retrieval of the latest version from your origin server. This ensures immediate content updates, lets you apply configuration changes, and removes non-compliant materials without waiting for the cache to expire. Prefetching proactively loads your resources onto DCDN points of presence (POPs) before peak traffic hits. This protects your origin server from overload and guarantees a fast, cached response for the first wave of users during launches or high-demand events.

Function introduction

Resource purge

A purge operation sends a cache invalidation command to DCDN POPs, rather than directly deleting files. When a POP receives the command, it marks the matching cached resources as invalid or expired. The next time a user requests the resource, the POP detects the invalid cache, retrieves the latest version from the origin server, and serves it to the user while caching the new version.

Default refresh method in the console: When you perform a directory refresh or regex-based refresh in the DCDN console, the mark-as-expired refresh method is used by default. This method only marks the cache as expired. When a POP retrieves the resource from the origin server, it includes the If-Modified-Since or If-None-Match request header. If the origin server returns 304 Not Modified, the POP retains the old cached copy. This method reduces back-to-origin traffic. However, users may still receive the old content in some scenarios, such as when a file on the origin server is updated without changing its name, when non-compliant content is removed, or after a configuration change. To completely purge the cache, we recommend that you call the RefreshObjectCaches operation and set the Force parameter to true to perform a forced refresh.

Scenarios

  1. Update and release content: After you update resources on your origin server, you can purge their URLs or directories. This ensures that users receive the latest versions instead of stale content.

  2. Remove non-compliant content: If you delete non-compliant content from your origin server, it might still be accessible from the DCDN cache. You can use the URL purge feature to clear the cache and ensure that the content is completely removed.

Resource prefetch

Prefetching prompts DCDN POPs to retrieve resources from your origin server based on a provided URL list and cache them. This process differs from the origin server actively pushing content. Prefetching improves the loading speed of new resources or promotional pages for first-time visitors and reduces back-to-origin traffic during high-traffic events, which protects your origin server.

Prefetch mechanism: By default, a prefetch operation caches resources on L2 back-to-origin nodes (the second-tier cache layer) instead of distributing them directly to all L1 POPs. When a user requests a resource for the first time, the L1 POP retrieves the content from an L2 back-to-origin node or the origin server and caches it. Therefore, prefetching mainly reduces the load on the origin server. Full cache coverage on L1 POPs depends on how user requests are actually distributed. An L1 POP caches the resource locally only after a user actually accesses that POP. Subsequent users in the same region can then get cache hits directly on the L1 POP for accelerated delivery.

Scenarios

  1. Onboard Alibaba Cloud DCDN: When you first start using Alibaba Cloud DCDN, you can prefetch your popular static resources to the POPs. This improves access speeds and enhances the user experience.

  2. Support promotional campaigns: Before you launch a major promotional campaign, you can prefetch all static resources for the campaign pages to the DCDN POPs. When the campaign begins, the POPs directly serve all user requests for these resources, which ensures fast page loads.

  3. Publish installation packages or large files: Before you release a new software version or update package, you can prefetch the resources to the DCDN POPs. After the official launch, the POPs directly handle user download requests, which accelerates download speeds and reduces the load on your origin server.

Cache tiers and effects

A prefetch operation mainly caches resources on L2 aggregation nodes, not on all L1 POPs. When a user requests a resource for the first time, the L1 POP retrieves the resource from an L2 node or the origin server. Therefore, the main purpose of prefetching is to reduce the load on the origin server, not to ensure that all L1 POPs return cache hits immediately.

  • Effect evaluation: Prefetching helps increase the cache hit ratio. However, for small files or files that are not frequently accessed, we recommend that you evaluate the cost of prefetching. Prefetching generates back-to-origin traffic, which is approximately equal to the size of a single file multiplied by the number of L2 nodes.

Scenarios

The following table describes common scenarios for refresh and prefetch.

Feature

Scenarios

Refresh

  • Resource updates and publishing

    After resources on the origin server are updated or upgraded, purge them by submitting their URLs or directories to allow users to bypass the stale cache and directly access the latest resources, which are then cached on the DCDN nodes.

  • Non-compliant resource removal

    If your origin server contains non-compliant content mentioned in Limits, the content may still be accessible from DCDN POPs even after you delete it from the origin server. Use URL refresh to update the cached resources.

Prefetch

  • Operational activities

    For a large-scale event, you can prefetch the static resources on the event page to DCDN nodes in advance. After the event starts, all static resources that users access are already cached on DCDN POPs and are served directly by these POPs.

  • Installation package releases

    Prefetch resources to the DCDN POPs before you publish a new version of an installation or update package. After the product is officially launched, download requests from many users are served directly by the DCDN POPs. This improves download speeds, significantly reduces the load on the origin server, and enhances the user experience.

Notes

  • Notes on cache purge:

    • Submitting many purge tasks clears a significant amount of cache. This causes a sudden increase in back-to-origin bandwidth and requests, which increases the load on your origin server. We recommend that you perform this operation during off-peak hours.

    • A purge task takes about 5 to 6 minutes to take effect. If the cache time-to-live (TTL) for a file or directory is less than 5 minutes, you do not need to perform a purge. You can wait for the cache to expire and update automatically.

    • URL purge, directory purge, and regex-based purge all support shared cache. If a domain name is configured with a shared cache, you can submit a purge task using the primary domain name or any associated domain name to clear the cache.

  • Notes on cache prefetch:

    • After a prefetch task is submitted and successfully executed, the DCDN nodes immediately retrieve the required resources from the origin server. Submitting many prefetch tasks at once generates many concurrent back-to-origin tasks, which causes a sudden increase in back-to-origin bandwidth and requests. We recommend that you perform this operation during off-peak hours.

    • By default, a prefetch request includes the Accept-Encoding:gzip header. To include other headers or enable multi-replica prefetching, call the Prefetch URLs OpenAPI operation and set the WithHeader request parameter.

    • During prefetching, if the origin server returns a redirection status code such as 307, the prefetch task does not follow the redirection and fails. However, if the origin server returns a 301 or 302 status code and you have enabled 301/302 redirects for origin fetch on DCDN, the prefetch task is not affected.

  • General notes:

    • If a domain name is configured with Rewrite Access URL, the node uses the rewritten URL to generate the CacheKey. You must submit the rewritten URL for refresh and prefetch operations.

    • To use a RAM user to refresh and prefetch resources, grant the required permissions to the RAM user first. For more information, see Grant permissions to a RAM user to refresh and prefetch resources.

    • You cannot abort a URL purge or cache prefetch task after it is submitted.

    • When you submit a cache purge or prefetch task, if the URI contains non-ASCII characters, such as spaces or Chinese characters, you must encode the URL. Otherwise, the task cannot be recognized.

    • URL signing for refresh and prefetch: Submit a refresh or prefetch URL that matches the actual cache key. For a domain name with URL signing configured, submit the original URL with its authentication parameters removed. Retain the accelerated domain name, file path, and business query parameters. If a business query parameter value contains /, encode that character as %2F before submission. Keep path separators unchanged.

      Before you submit a refresh or prefetch request, the console validates only the URL format and submits the URL as entered. It does not automatically remove authentication parameters, re-encode business query parameters, or normalize the URL. Do not submit a client access URL that contains authentication parameters. The URL might not match the actual cache key and might fail to match the target cached resource.

      The following example shows the case when the method F URL signing is applied to the domain name. In this example, k and t are the signature and timestamp parameter names configured for that domain name.

      1. Client access URL:

        https://image.example.com/cat.jpg?x-oss-process=image/resize,m_fill,w_390,h_520,limit_1/auto-orient,1/sharpen,100/quality,q_80&k=123456789abcdefg&t=123abc
      2. URL after removing authentication parameters: Remove k and t, and retain the business query parameters.

        https://image.example.com/cat.jpg?x-oss-process=image/resize,m_fill,w_390,h_520,limit_1/auto-orient,1/sharpen,100/quality,q_80
      3. Final refresh or prefetch URL: Encode / in the value of the x-oss-process business query parameter as %2F. Keep the path separator in /cat.jpg unchanged.

        https://image.example.com/cat.jpg?x-oss-process=image%2Fresize,m_fill,w_390,h_520,limit_1%2Fauto-orient,1%2Fsharpen,100%2Fquality,q_80

Refresh resources

  1. Log on to the DCDN console.

  2. In the navigation pane on the left, choose Tools > Purge and Prefetch.

  3. On the Purge Cache tab, configure the refresh rules.

    Parameter

    Description

    Operation

    Select Purge.

    Operation Method

    You can refresh by URL, Directory, or Regular Expression.

    URL

    • By default, each Alibaba Cloud account can refresh up to 10,000 URLs and 100 directories (including subdirectories) per day. If the daily peak bandwidth of your account exceeds 200 Mbps, you can request a quota increase in Quota Management. Alibaba Cloud evaluates and configures the quota based on your actual business needs.

    • By default, an Alibaba Cloud account can submit up to 20 regex-based refresh tasks per day. If the peak bandwidth of your account exceeds 10 Gbps, you can fill out a form to request a quota increase.

    • URL refresh

      • The URL must start with http:// or https://.

      • To refresh multiple URLs, enter one URL per line.

    • Directory refresh

      • The URL must start with http:// or https:// and end with a forward slash (/).

        • To refresh all files in the root directory: http://example.com/.

        • To refresh all files in the /path/test/ subdirectory: http://example.com/path/test/.

      • To refresh multiple URLs, enter one URL per line.

      • You can submit up to 100 directory refresh tasks at a time, and up to 100 per minute for a single domain name.

      • By default, directory refresh uses the "refresh changed resources" method. If a user request matches a resource in the directory, the DCDN node retrieves the Last-Modified information of the resource from the origin server. If the information is the same as that of the currently cached resource, the node directly returns the cached resource. If it is different, the node pulls the new resource from the origin server, returns it to the user, and caches the new resource.

    • Regex-based refresh

      For more information, see Regex-based refresh.

  4. Click Submit.

  5. View the refresh progress.

    After you submit a refresh task, you can view its details and progress on the Records tab. The task may take a long time if you refresh many resources.

Prefetch resources

  1. Log on to the DCDN console.

  2. In the navigation pane on the left, choose Tools > Purge and Prefetch.

  3. On the Purge Cache tab, configure the prefetch rules.

    Parameter

    Description

    Operation

    Select Prefetch.

    Operation Method

    Only URL prefetch is supported.

    URL

    • The URL must start with http:// or https://. The URL must be the exact path of a resource file. Directories ending with a forward slash (/) are not supported.

    • To prefetch multiple URLs, enter one URL per line.

    • URL prefetch quota (daily): An Alibaba Cloud account can submit up to 1,000 URL prefetch tasks per day, with a maximum of 100 per submission.

      If the daily peak bandwidth of your account exceeds 500 Mbps, you can request a quota increase in Quota Management. Alibaba Cloud evaluates and configures the quota based on your actual business needs.

    • Prefetch queue rule: The prefetch queue for each account can hold a maximum of 100,000 URLs. DCDN prefetches URLs in the order they are submitted. When the number of URLs to be prefetched in the queue reaches 100,000, DCDN rejects new prefetch tasks.

    • Prefetch speed: The prefetch speed depends on the average file size. Smaller files are prefetched faster.

  4. Click Submit.

  5. View the prefetch progress.

    After you submit a prefetch task, you can view its details and progress on the Records tab. The task may take a long time if you prefetch many resources.

Related API operations

You can also call API operations to refresh and prefetch resources.

API

Description

RefreshDcdnObjectCaches

Refreshes the content of specified URLs on cache nodes. Supports batch URL refresh.

Note

URL refresh, directory refresh, and regex-based refresh all support shared cache. If shared cache is configured for a domain name, you can submit a refresh task using the primary domain name or any associated domain name to purge the cache.

PreloadDcdnObjectCaches

Prefetches content from the origin server to L2 cache nodes. This ensures cache hits on first access and reduces the load on the origin server.

DescribeDcdnRefreshQuota

Queries the daily quotas and remaining quotas for URL refreshes, URL prefetches, and directory refreshes.

DescribeDcdnRefreshTasks

Queries whether a refresh or prefetch task has taken effect across the entire network.

DescribeDcdnUserQuota

Queries the resource quotas and usage for a user.

DescribeDcdnRefreshTaskById

Queries whether a refresh or prefetch task has taken effect across the entire network.