Alibaba Cloud Content Delivery Network (CDN) allows you to create cache expiration rules to expire static resources of specified file types or in specified directories. You can also specify a priority for each cache expiration rule. When a static resource expires, the resource is automatically deleted from the corresponding CDN node. This topic describes the rules of expiring cached resources on a CDN node and how to create a cache expiration rule.

Background information

When you update a resource file on the origin, we recommend that you include the version number in the name of the update file instead of using the same name as the existing resource file. For example, you can name two update files as img-v1.0.jpg and img-v2.1.jpg. Afterward, you can set a cache expiration rule for the resource file.

The following figure shows the cache expiration policy of resources on CDN nodes.Cache policy
  • If an origin server has a caching rule configured, the cache expiration rule on the CDN node has a higher priority than the caching rule configured on the origin server. If an origin server has no caching rule configured, you can set a cache expiration rule by directory or by file extension. You can set a full-path cache expiration rule.
  • A CDN node may remove the cached files that are not updated frequently on the node before they expire.


  1. Log on to the Alibaba Cloud CDN console.
  2. In the left-side navigation pane, click Domain Names.
  3. On the Domain Names page, find the target domain name and click Manage.
  4. In the left-side navigation pane of the specified domain, click Cache.
  5. On the Cache Expiration tab, click Create Rule.
  6. In the Create Expiration Rule dialog box that appears, set Type to Directory or File Extension.
    Item Description
    • Directory: specifies resources cached in a specified directory.
    • File Extension: specifies resources cached in files with specified file extensions.
    • After you set Type to Directory, enter a directory name in the Object field. The directory name must start with a forward slash (/), for example, /directory/aaa.
    • After you set Type to File Extension, enter one or more file extensions in the Object field. Separate multiple file extensions with commas (,), for example, JPG,txt.
    Expire In Specifies a TTL value of the cached resources. A CDN node can cache resources for up to three years. We recommend that you set this parameter according to the following rules:
    • Specify a TTL value of one month or longer for static files such as images and applications that are not frequently updated.
    • Specify a TTL value as needed for static files such as JavaScript and CSS files that are frequently updated.
    • Specify a TTL value of 0 second for dynamic files such as PHP, JSP, and ASP files. As a result, the CDN node will not cache these files.
    Weight Specifies the priority of the rule.
    • Set this parameter to an integer from 1 to 99. A higher value indicates a higher priority and a rule with a higher priority prevails over rules with lower priorities.
    • We recommend that you do not set the same priority for different rules. If different rules have the same priority value, one of these rules is applied at random.
    For example, if you set the following rules for the domain, Rule 1 takes effect preferentially over the other two rules:
    • Rule 1: Type is set to File Extension, Object is set to jpg,png, Expire In is set to 1 Months, and Weight is set to 90.
    • Rule 2: Type is set to Directory, Object is set to /www/dir/aaa, Expire In is set to 1 Hours, and Weight is set to 70.
    • Rule 3: Type is set to Directory, Object is set to /www/dir/aaa/example.php, Expire In is set to 0 Seconds, and Weight is set to 80.
    Cache Expiration
  7. Click OK.

    You can click Modify or Delete in the Actions column for the cache expiration rule to modify or delete the rule.