When the ETag or Last-Modified response headers are not returned, the requested static resource fails to be cached. This reduces the CDN cache hit rate. To improve the CDN cache hit rate, you can configure a cache rule for this resource. As a result, the resource can be cached on CDN according to the cache rule.
When no cache rule is configured on CDN, a static file cannot be cached on the CDN node if the ETag and Last-Modified response headers are not returned. Configure a cache rule for the static file as follows.
- Any one of s-maxage=0, max-age=0, no-cache, no-store, and private
- s-maxage or s-maxage=0
- Pragma: no-cache
- 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.