You can configure the maximum age for one or more cached resources on CDN nodes. If the maximum age has reached and a visitor requests a resource from a CDN node, CDN requests the most recent resource from the origin server and caches that content on the CDN node. You can cache all files or cache desired content by directory, file type, and full path.
Cache policies on CDN nodes comply with HTTP. You can control cache aging by configuring the Cache-Control: max-age field in an HTTP response header. By leveraging cache rules, you can optimize cache periods for different services. Appropriate cache policies can increase the hit ratio and reduce the retrieval rate, which reduces bandwidth utilization.
After receiving an access request, a CDN node will check whether the requested content has expired in the cache. If the requested content is valid in the cache, it will be returned directly from that CDN node to the user, speeding up site response. If the requested content in the cache has expired, the CDN node will send a request to retrieve new content from an origin server so it can update its local cache and serve new content to the user.
- Up to 20 cache rules can be added to each domain name.
- The maximum cache age affects the retrieval rate directly. If the maximum cache age is short, the cached content on CDN nodes becomes invalid in a short time, resulting in frequent retrieval, which increases the origin server load and prolong the access latency. However, if the maximum cache age is too long, cached content may be outdated as a result.
- If the maximum cache age is set to 0, CDN retrieves content from the origin server for all user requests, which may interrupt the accelerate service.
- Resources cached on nodes may be deleted due to infrequent access.
- Log in to the HUAWEI CLOUD console. On the homepage of the HUAWEI CLOUD console, choose Storage > CDN. The CDN console is displayed.
- In the navigation pane, click .
- In the domain list, click the domain name to be modified or click Settings at the end of the row of the domain name.
- Click the Cache Settings tab.
- In the Cache Rules area, click Edit. The Configure Cache Policy dialog box is displayed, as shown in Figure 1.
- Click Add and configure a cache policy based on service requirements, as shown in Figure 1. Table 1 describes the parameters.
Table 1 Cache policy parameters
All resources cached on the CDN node
By default, CDN has a rule for newly added acceleration domain names. The rule specifies that the maximum cache age for All files is 30 days. You can modify but not delete this rule.
Resources of a specified file type
If the service type of a newly added acceleration domain name is Website, File download, or On-demand service and its origin server is a private one, CDN adds a rule to it by default. The rule specifies that the maximum age is 0 for common dynamic files, such as the .php .jsp .asp and .aspx files. That is, CDN retrieves such files from the origin server for every request. You can modify or delete this rule.
All file formats are supported. A maximum of 20 file name suffixes can be entered. Use semicolons (;) to separate one suffix from another. Each suffix must start with a period (.).
For example, .jpg;.zip;.exe
Resources in a specified directory
A directory must start with a slash (/) and multiple directories must be separated by semicolons (;). The total number of directories cannot exceed 20.
For example, /test/folder01;/test/folder02
Complete path of a specific file
The value must start with a slash (/) and cannot end with an asterisk (*). Files in the specified directory or files with the wildcard * can be matched. Only one full path can be configured for a single full path cache rule.
For example, /test/index.html or /test/*.jpg
Priority of a cache rule
Each cache policy must have a unique priority. The priority setting is mandatory. If a resource is specified in multiple cache rules, the rule with the highest priority is applied.
Priority is represented by an integer from 1 to 100. A greater number indicates a higher priority.
Length of time a file can be cached. If the maximum age has reached and a visitor requests a resource from a CDN node, CDN requests the most recent resource from the origin server and caches that content on the CDN node.
The maximum age of a cached file cannot exceed 365 days. You are advised to set the time according to the following rules:
- For static files (such as .jpg and .zip files) that are not frequently updated, set the maximum age to more than one month.
- For static files (such as .js and .css files) that are frequently updated, set the maximum age based on service requirements.
- For dynamic files (such as .php, .jsp, and .asp files), set the maximum age to 0 seconds.
- (Optional) You can delete a cache rule by clicking Delete at the end of the cache rule.
- Click OK.
- Enable or disable URL Parameter Filtering based on your service needs. If this function is enabled, parameters after the question mark (?) in the URL will be filtered out.
- If this function is disabled, CDN nodes will retrieve content from origin servers based on users' request URLs, and content corresponding to different parameters in URLs will be cached after the end user's request is fulfilled. When users request to access the same URL, content will be provided based on different parameters after the question mark (?) in the URL.
- If this function is enabled, parameters after the question mark (?) in a URL will be ignored when CDN nodes retrieve content from origin servers. Only one version of resource content will be cached after the end user's request is fulfilled. When users request to access the same URL, the cached resource will be returned, which is not differentiated according to parameters after the question mark (?) in the URL.