PoP Cache Rules
You can configure the TTL for one or more cached resources on CDN PoPs. If the TTL of a file has reached, CDN requests the most recent content of the file from the origin server when a user requests the file. CDN returns the content to the user and caches it on PoPs. You can cache all files and the homepage, or cache desired content by directory, file type, and full path.
Background
Cache policies on CDN PoPs 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 periods can increase the hit ratio and reduce the origin pull rate, which reduces bandwidth utilization.
After receiving a request, a CDN PoP 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 PoP to the user, speeding up site response. If the requested content in the cache has expired, the CDN PoP will send a request to obtain new content from an origin server so it can update its local cache and serve new content to the user.
Precautions
- Up to 60 cache rules can be added to each domain name.
- The cache TTL affects the origin pull rate directly. If the TTL is short, cached content on CDN PoPs becomes invalid in a short time, resulting in frequent origin pulls, which increases the origin server load and prolongs the access latency. However, if the TTL is too long, cached content may be outdated as a result.
- If the TTL is set to 0, CDN pulls content from the origin server for all user requests, which may interrupt the acceleration service.
- Resources cached on PoPs may be deleted due to infrequent access.
- If you have modified the cache rule,
- Your modifications are effective for new content cached.
- You can purge to apply modifications to all resources (including the existing PoP cache).
Procedure
- Log in to Huawei Cloud console. Choose .
The CDN console is displayed.
- In the navigation pane, choose .
- In the domain list, click the target domain name or click Configure in the Operation column.
- Click the Cache Settings tab.
- In the Cache Rules area, click Edit. The Configure Cache Rule dialog box is displayed.
- Click Add to add a cache rule. Table 1 describes the parameters. You can click Suggested Rules to view the recommended configuration.
Figure 1 Configuring a cache rule
- (Optional) Delete a cache rule if you no long use it.
- Click OK.
Examples
Scenario 1: Assume that you have configured CDN acceleration for the domain name www.example.com. The following figure shows the cache rule configuration.
The homepage of the website is not cached, and URL parameters are not ignored in requests for all pages.
Scenario 2: Assume that you do not want to cache files of a specific type.
- You have configured CDN acceleration for the domain name www.example.com. Due to service requirements, files in .do format do not need to be cached, and URL parameters should be ignored in requests for all files.
You can add a cache rule for your website on the CDN console, with Type set to File type, Content to .do, and TTL to 0.
The new rule only applies to new content. After the new rule is added, purge the cached URL or directory where the .do file is located on the CDN console so that the new rule can take effect for all .do files.
- You have configured CDN acceleration for your website, the login page of your website is displayed cyclically, and your customers cannot log in to the website. After CDN acceleration is disabled, customers can log in to the website.
This is because CDN PoPs have cached the login page. To resolve the issue, add a cache rule for your website on the CDN console and set the cache TTL of the login page to 0 in the rule. Take the login page of the Huawei Cloud console as an example. The login page of the Huawei Cloud console is https://auth.huaweicloud.com/authui/login.html#/login. You can add a cache rule on the CDN console, with Type set to Full path, Content to /authui/login.html#/login, and TTL to 0.
Scenario 3: Assume that you have configured the following cache rules for your acceleration domain name www.example.com but do not know which rule takes effect.
When a user requests www.example.com/test/cdn.jpg, rules of the All files, File type, and Full path type are all matched. The priority of the Full path rule is 8, which is the highest among the three rules. Therefore, the rule of the Full path type (/test/*.jpg) is used.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.