This topic describes how to refresh and preload resources in Alibaba Cloud CDN.

Feature overview

  • Refresh: marks all resources that are cached on the points of presence (POPs) as expired. When a POP receives a request, the POP redirects the request to the origin server to retrieve the requested resources. The retrieved resources are returned to the client and cached on the POP. The refresh feature reduces the cache hit ratio.
  • Prefetch: prefetches resources from origin servers and caches the resources on the POPs. When a POP receives a request, the POP directly returns the requested resources to the client because the resources are already cached on the POPs. The prefetch feature increases the cache hit ratio.

Common scenarios

The following table describes the scenarios where the refresh or prefetch feature is commonly used.
FeatureCommon scenario
Refresh
  • Update and publish resources

    After resources on your origin server are updated, you can submit the URLs or directories of the updated resources to Alibaba Cloud CDN. Then, Alibaba Cloud CDN refreshes the resources that are cached on the POPs. This ensures that visitors can retrieve up-to-date resources from the POPs.

  • Delete resources that violate the limits of Alibaba Cloud CDN

    After you delete resources that violate the limits described in Limits from your origin server, visitors can still access the resources because the resources are cached on the POPs. In this case, you must use the refresh feature to update the CDN cache so that the resources are deleted from the POPs.

Prefetch
  • Provide support for major events

    If you want to hold a major event, you can push the static resources of the event page to the POPs. After the event starts, visitors can access the static resources, which are already cached on the POPs. This accelerates content delivery.

  • Release installation packages

    Before you release an installation or upgrade package of a product, you can push the package to the POPs. After the product is launched, visitors can download the package from the POPs. This accelerates content delivery and reduces loads on origin servers when a large number of visitors want to access your resources.

Usage notes

  • After a refresh task is submitted and completed, specific resources are removed from POPs. When a POP receives a request for the removed resources, the POP forwards the request to the origin server to retrieve the resources. The retrieved resources are returned to the client and cached on the POP. Multiple refresh tasks may cause a large number of resources to be removed from the POPs. This increases the number of requests that are forwarded to the origin server. The back-to-origin routing process consumes more bandwidth resources and the origin server may be overwhelmed.
  • A refresh task takes effect 5 to 6 minutes after being submitted. If the TTL for the resources you want to refresh is less than five minutes, you can wait until the TTL expires instead of performing the refresh operation.
  • After a refresh task is submitted and completed, the POPs immediately start to retrieve resources from the origin server. Therefore, a large number of refresh tasks cause a large number of concurrent download tasks. This increases the number of requests that are redirected to the origin server. The back-to-origin routing process consumes more bandwidth resources and the origin server may be overwhelmed.
  • The time required for prefetch task to complete is proportional to the size of the prefetched file. In actual practice, most prefetch tasks take 5 to 30 minutes to complete.
  • Resource Access Management (RAM) users must acquire required permissions before they can refresh or prefetch resources. For more information, see Authorize a RAM user to prefetch and refresh resources.
  • URL refresh, directory refresh, and refresh that contains regular expressions support shared cache. If shared cache is configured for a domain name, you can submit a refresh task with the primary domain name or any associated domain name to refresh the cache.

Refresh resources

Note For more information about how to automate refresh and prefetch tasks, see Run scripts to refresh and prefetch content.
  1. Log on to the Alibaba Cloud CDN console.
  2. In the left-side navigation pane, click Refresh & Prefetch.
  3. On the Refresh/Prefetch tab, configure the refresh rules.
    Refresh and prefetch
    ParameterDescription
    OperationSelect Refresh.
    Operation MethodSelect URL, Directory, or Regular Expression.
    URL
    • If your daily peak bandwidth exceeds 200 Mbit/s, you can request a quota increase by referring to Quota management. Alibaba Cloud determines whether to approve your application based on your business requirements.
    • Refresh resources based on URLs
      • Each URL must start with http:// or https://.
      • Enter only one URL on each line.
      • Each Alibaba Cloud account can submit up to 10,000 URLs per day and up to 1,000 URLs at a time. You can submit up to 1,000 URLs for each domain name per minute.
    • Refresh resources based on directories
      • Each URL must start with http:// or https:// and end with a forward slash (/).
        • Refresh all files in the root directory: http://example.com/.
        • Refresh all files in the subdirectory /path/test/: http://example.com/path/test/.
      • Enter only one URL on each line.
      • Each Alibaba Cloud account can submit up to 100 directories per day and up to 100 directories at a time. Subdirectories are supported. You can apply for a quota increase. After your application is approved, you can submit up to 1,000 directories at a time.
      • If you set the ObjectType parameter to Directory, the resources in the directory that you want to refresh are marked as expired. You cannot delete the directory. If clients request resources on POPs that are marked as expired, Alibaba Cloud CDN checks whether the resources on your origin server are updated. If resources are updated, Alibaba Cloud CDN retrieves the most recent version of the resources and returns the resources to the clients. Otherwise, the origin server returns the 304 status code.
    • Refresh resources based on regular expressions

      For more information, see Configure URL refresh rules that contain regular expressions.

  4. Click the Submit.
  5. Check the refresh progress.
    After you submit a refresh task, you can check the progress and details on the Records tab. The progress depends on the number of objects to be refreshed. It may take some time to complete the task.
    Note If Auto CDN Cache Update is enabled in the Object Storage Service (OSS) console, you cannot check the automatic refresh tasks in the Alibaba Cloud CDN console.

Prefetch resources

Note For more information about how to automate refresh and prefetch tasks, see Run scripts to refresh and prefetch content.
  1. Log on to the Alibaba Cloud CDN console.
  2. In the left-side navigation pane, click Refresh & Prefetch.
  3. On the Refresh/Prefetch tab, configure the prefetch rules.
    Prefetch
    ParameterDescription
    OperationSelect Prefetch.
    Operation MethodOnly URL is supported.
    URL
    • Each URL must start with http:// or https://.
    • Enter only one URL on each line.
    • By default, each Alibaba Cloud account can submit up to 1,000 URLs per day. If the daily peak bandwidth value of your workloads exceeds 200 Mbit/s, you can request a quota increase by referring to Quota management. Alibaba Cloud reviews your application and then increases the quota accordingly.
    • Each Alibaba Cloud account can submit up to 100 URLs in a request.
    • For each Alibaba Cloud account, the prefetch queue can contain up to 50,000 URLs. Content is prefetched based on the time when the URLs are submitted. The URL that is submitted the earliest has the highest priority. If the number of URLs in the queue reaches 50,000, you cannot submit more URLs until the number drops below 50,000.
    • The execution speed of a prefetch task varies based on the average size of the files that you want to prefetch. Smaller average size of files allows you to obtain faster prefetch speeds.
  4. Click the Submit.
  5. Check the prefetch progress.
    After you submit a prefetch task, you can view the progress and details on the Records tab. The progress depends on the number of objects to be prefetched. It may take some time to complete the task.

API references

You can call API operations listed in the following table to refresh and prefetch resources.
APIDescription
PushObjectCachePrefetches resources from origin servers to the POPs. This reduces loads on origin servers because visitors can hit cache upon their first visits.
RefreshObjectCachesRefreshes files on Alibaba Cloud CDN POPs. After files are refreshed, the original file content immediately becomes invalid. If clients request the original file content, Alibaba Cloud CDN redirects the requests to the origin server where the content is stored. Then, Alibaba Cloud CDN caches the latest content to the POPs and returns it to the clients. Alibaba Cloud CDN allows you to refresh content from multiple URLs at a time.
Note URL refresh, directory refresh, and refresh that contains regular expressions support shared cache. If shared cache is configured for a domain name, you can submit a refresh task with the primary domain name or any associated domain name to refresh the cache.
DescribeRefreshTasksQueries the status of refresh or prefetch tasks.
DescribeRefreshTaskByIdQueries the status of refresh or prefetch tasks by ID.
DescribeRefreshQuotaQueries the maximum and remaining numbers of URLs and directories that can be refreshed, the maximum and remaining numbers of URLs that can be prefetched, and the maximum and remaining numbers of URLs and directories that can be blocked on the current day.
DescribeCdnUserQuotaQueries the maximum and remaining quota.