Configure cache rules to manage validity periods and priorities for resources cached on CDN points of presence (POPs), improving cache hit ratios. After a resource expires, it is automatically deleted from the POP and re-cached from the origin server.
Overview
-
If you do not configure cache rules on the origin server or POPs, the default validity period of 3,600 seconds is used. After you add a domain name to ApsaraVideo VOD, you can change the default validity period. The amount of origin traffic and fees vary based on the validity period. We recommend that you specify a validity period based on your business requirements. A short validity period may cause POPs to frequently redirect requests to the origin server and increase origin traffic.
-
The default cache rule specifies the validity period of cached resources. Cache rules configured on POPs take priority over cache configurations on the origin server. If no cache configuration is specified on the origin server, you can configure a cache rule based on directory or file name extension in the ApsaraVideo VOD console.
-
Infrequently accessed cached files may be removed from the POP before they expire.
-
If a client request includes the If-Match header and the origin server response includes the ETag header, the POP returns the cached resource directly when the two values match. If the values differ, the POP retrieves the latest version from the origin server and returns it to the client, replacing the cached copy. POPs compare the If-Match and ETag values before applying cache rules.
When you update a resource on your origin server, we recommend that you include a version number in the file name instead of reusing the existing name. For example, use img-v1.0.jpg and img-v2.1.jpg. Then, configure a cache rule for the resource. The following figure shows cache rules for resources on POPs.

Procedure
-
Log in to the ApsaraVideo VOD console.
-
In the left-side navigation pane, under Configuration Management, click CDN Configuration > Domain Names.
-
Find the domain name that you want to configure and click Configure in the Actions column.
-
On the page that appears, click . On the Cache Validity tab, click Add.
-
Configure a cache rule. Set the Type parameter to Folder or File Extension.

The following table describes the parameters.
Parameter
Description
Type
-
Folder: caches resources in a specified directory.
-
File Extension: caches resources with specified file name extensions.
Address
-
If you set Type to Folder, enter a directory that starts with a slash (/), such as /directory/aaa. You can enter a full path.
-
If you set Type to File Extension, use commas (,) to separate multiple file name extensions. Example:
JPG,TXT.
Validity Period
The validity period of cached resources. The maximum value is three years. We recommend that you set this parameter based on the following rules:
-
Specify a validity period of one month or longer for static files such as images and application packages that are not frequently updated.
-
Specify a validity period for static files such as JavaScript and CSS files that are frequently updated based on your actual workloads.
-
Specify a validity period of 0 seconds to disable caching for dynamic files such as PHP, JSP, and ASP files.
Weight
The priority of the cache rule.
Note-
The value must be an integer from 1 to 99. A higher value indicates a higher priority. A rule with a higher priority takes precedence over rules with lower priorities.
-
Do not assign the same priority to different rules. If two rules have the same priority, one is randomly applied.
-
After a cache rule takes effect, other rules are not applied.
For example, if you configure the following rules for
example.aliyun.com, rule 1 takes precedence over the other rules.-
Rule 1: The Type parameter is set to File Extension, the Address parameter is set to jpg.png, the Validity Period Parameter is set to 1 Month, and the Weight parameter is set to 90.
-
Rule 2: The Type parameter is set to Folder, the Address parameter is set to /www/dir/aa, the Validity Period Parameter is set to 1 Hour, and the Weight parameter is set to 70.
-
Rule 3: The Type parameter is set to Folder, the Address parameter is set to /www/dir/aaa/example.php, the Validity Period Parameter is set to 0 Seconds, and the Weight parameter is set to 80.
-
-
Click OK.