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.
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.
- 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.
- Log on to the Alibaba Cloud CDN console.
- In the left-side navigation pane, click Domain Names.
- On the Domain Names page, find the target domain name and click Manage.
- In the left-side navigation pane of the specified domain, click Cache.
- On the Cache Expiration tab, click Create Rule.
- In the Create Expiration Rule dialog box that appears, set Type to Directory or File
Item Description Type
- 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,
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 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.Note
For example, if you set the following rules for the
- 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.
example.aliyun.comdomain, 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.
- Click OK.
You can click Modify or Delete in the Actions column for the cache expiration rule to modify or delete the rule.