Setting the Cache TTL
CDN caches origin content on globally distributed PoPs so that users can obtain the content from nearby PoPs. On the CDN console, you can set the cache TTL for origin content of different file types based on service requirements.
Impact of Origin Servers on CDN PoP Caches
- If you have configured a cache rule on the origin server, the following scenarios are possible:
- If you have set Cache-Control to no-cache, private, or no-store on the origin server and enabled Origin Cache Control on the CDN console, CDN PoPs do not cache origin content. Instead, CDN PoPs pull content from the origin server each time the content is requested. This does not achieve acceleration.
By default, Origin Cache Control is disabled on the CDN console.
- If you have set a specific TTL on the origin server, this TTL will be overwritten by that set on the CDN console.
- If you have set Cache-Control to no-cache, private, or no-store on the origin server and enabled Origin Cache Control on the CDN console, CDN PoPs do not cache origin content. Instead, CDN PoPs pull content from the origin server each time the content is requested. This does not achieve acceleration.
- If no cache rules are set on the origin server, cache rules set on the CDN console are used.
Setting a Cache TTL Based on Service Type
Default cache TTL
- If the service type is website acceleration, file download acceleration, or on-demand service acceleration, and the origin server address is an IP address or domain name, the following default cache rules are available:
- The default cache TTL for common dynamic files (for example, .php, .jsp, .asp, and .aspx files) is 0. CDN pulls content from the origin server directly when receiving requests for such dynamic files. You can modify and delete this rule.
- The default cache TTL for other files is 30 days. You can modify but cannot delete this rule.
- If your origin server is an OBS bucket, the default cache TTL for all files is 30 days. You can modify but cannot delete this rule.
You can add a custom cache rule with a higher priority so that custom rule will be used.
- If the service type is whole site acceleration, a cache rule with Type set to All files and TTL set to 0 is available by default. You can modify and delete this rule.
You can configure a cache TTL based on the service type and the following suggestions.
- Website acceleration
- Do not cache dynamic files such as .php, .aspx, .asp, .jsp, .do, .dwr, .cgi, .fcgi, .action, .ashx, .axd, and .json files.
- Cache .shtml, .html, .htm, and .js files for seven days.
- Cache other static files for 30 days.
- Download acceleration
- Do not cache dynamic files such as php, aspx, asp, jsp, and .do files.
- Cache files of the following types for 30 days: .7z, .apk, .wdf, .cab, .dhp, .exe, .flv, .gz, .ipa, .iso, .mpk, .mpq, .pbcv, .pxl, .qnp, .r00, .rar, .xy, .xy2, .zip, and .cab.
- On-demand service acceleration
- Do not cache dynamic files such as .php, .aspx, .asp, .jsp, and .do files.
- Cache the following file types for seven days: .mwv, .html, .htm, .shtml, .hml, .gif, .swf, .png, .bmp, and .js.
- Cache the following file types for 30 days: .mp3, .wma, .7z, .apk, .wdf, .cab, .dhp, .exe, .flv, .gz, .ipa, .iso, .mpk, .mpq, .pbcv, .pxl, .qnp, .r00, .rar, .xy, .xy2, .zip, and .cab.
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 cache rules. Table 1 describes the parameters.
Figure 1 Configuring a cache rule
- (Optional) Delete a cache rule if you no long use it.
- Click OK.
If you have modified a cache rule,
- Your modifications are effective for new content cached.
- You can purge to apply modifications to the existing cache.
Examples
Scenario 1: Assume that you have added a web portal to Huawei Cloud CDN for acceleration, but you do not want to cache it.
You can add a cache rule for this web portal on the CDN console, with Type set to Homepage and TTL to 0.
Scenario 2: Assume that you do not want to cache files of a specific type or a specific web page.
- You have configured CDN acceleration for your website and set the cache TTL of .do files to one day. However, due to service requirements, you do not need to cache .do files anymore.
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.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot