Last update:2024-07-17 17:19:56
The CDNetworks CDN platform enables you to customize caching rules for your website’s contents on our edge servers. You can configure cache duration and other strategies based on various file types, request URLs, and other parameters to achieve your desired caching behavior on the CDN platform. Additionally, when your website is accelerated and distributed via the CDNetworks CDN platform, the platform applies some default caching rules. If no custom rules are defined, the contents from your origin will adhere to these default caching rules on CDN servers.
The CDNetworks CDN platform utilizes different caching strategies and default cache durations based on your origin server’s response configuration and the content of user requests.
Cache-Control:no-store,no-cache,must-revalidate,post-check=0,pre-check=0
and Pragma:no-cache
, or if the request includes an Authorization
header without Cache-Control:public
in the response, the CDN servers will not cache this content by default.Authorization
header with Cache-Control:public
in the response, the caching will follow the platform’s default caching strategy and duration or your custom caching rules (note that some specific file types may be configured not to be cached on CDN servers).Request Scope/Type | File Types/Protocol | Default Cache Strategy/Duration |
---|---|---|
Keep Query String Requests | php, aspx, asp, jsp, do, dwr, cgi, fcgi, action, ashx, axd, json | No Cache |
Keep Query String Requests | mp4, ts, f4v, f4vcrc7z, apk, wdf, cab, dhp, exe, flv, gz, ipa, iso, mpk, MPQ, pbcv, pxl, qnp, r00, rar, xy, xy2, zip, CAB | 30 days |
Keep Query String Requests | shtml, html, htm, js | 12 hours |
Keep Query String Requests | gif, swf, png, bmp | 24 hours |
Ignore Query String Requests | cgi | 10 minutes |
All Requests | mp3, wma | 12-24 hours |
All Requests | wmv | 24 hours |
All Requests | FTP Protocol | 24-168 hours |
All Requests | Gopher Protocol | 0-24 hours |
All Requests | Other File Types/Protocol | 24 hours |
You can find the appropriate way to customize and modify these default caching rules in this tutorial.
Log in to the CDNetworks Console and select the appropriate product.
Navigate to the Configuration, locate the domain you wish to configure, and click on Edit Configuration at the top or the Edit button to the right of the domain .
Enter the configuration modification page, find the Customized Caching under Cache Optimization, and click the Add button;
On the rule editing page, you can easily add the following configuration options based on your needs.
Effective Range
The CDNetworks CDN platform provides the following options for the effective scope of your custom cache rules:
Options | Description |
---|---|
All Requests | Indicates that all requests initiated towards the associated domain are applicable to this rule. |
Only Homepage | This rule is applicable only to requests in the root directory, e.g.,http://domain/ or https://domain/ . |
Specified File Types | This rule applies to the requests for specified file types, you can choose from listed ones or customize your file types in this field. Separate multiple file types with ; , e.g.,ace;aac . |
Specified URI | You can set specific URIs for this cache rule, supporting Exact Matching or Ignore the Parameter Matching. Multiple URIs can be separated by line breaks. Exact Matching: The user’s requested URI must fully match the configured URI for this rule to take effect. Ignore the Parameter Matching: If the URI with a query string is requested, the query string parameters are ignored. Only the part before the question mark is matched with the configured URI, this request will apply to this cache rule. Note that the input URI does not contain http:// or https:// , only the URI part, e.g., for the complete URL https://domain/browse/index.html , configure only /browse/index.html . |
Specified Directory | This rule applies to all requests aimed at specified directories while directories must begin and end with a / and can be composed of any combination of letters, numbers, and certain special symbols (including underscores, hyphens, percentage signs, and dots), e.g.,/file/1%1/ ,indicates that the rule applies to requests for the directoryhttp://domain/file/1%1/ and all files within it. Please note that, you need to separate multiple directories with a line break. |
URL Regular Expression | You can also choose to directly enter a regular expression, not required to start with / . The platform will automatically prefix the URL with ^https?://[^/]/ , e.g.,.*.jpg$ , indicating that requests for JPG files across all domains associated with this rule will match this policy. |
In addition to selecting the effective scope of your custom cache rule from the above list, you can make some more configuration in Advanced Range Settings. This works in conjunction with the Effective Range you set, forming the actual effective scope of the cache rule under an AND relationship. The Advanced Range Settings offers the following options:
Parameter | Description |
---|---|
UA or Exception UA | Supports regular expressions, spaces and TABs are translated to \s , e.g., ^Mozilla/4.0$ to apply or not apply the rule to requests carrying this UA header;Multiple UAs can be configured simultaneously, each UA on a separate line. |
Exception URL (Regex) | In this configuration item, you can exclude certain specific request URLs from applying the cache rule. The rules for filling out regular expressions are the same as the URL Regular Expression configuration item above. |
Cache Duration
For requests that match your defined Effect Range, you can customize the cache duration on CDN servers on the CDNetworks CDN platform. Currently, there are three cache duration-related strategies you can set, as detailed below:
Parameter | Description |
---|---|
Cache | Indicates fixed cache duration for this option. If your website files are updated at a stable frequency, consider setting a fixed cache duration to optimize CDN hit rates and reduce back-to-origin traffic. |
Follow Origin Cache Rules | If your website files have set cache duration-related parameters, such as Expires or Cache-Control , the CDN servers will follow the cache duration set by your origin. Note that you still need to set a cache duration here so that if your origin server does not include cache duration parameters for some reason, the contents from your origin will still be cached according to the duration set here. |
Do Not Cache | If your website files need real-time updates, please configure Do Not Cache. Every user request to the CDN edge servers will trigger fetching the contents from your origin and respond to the user without caching on the CDN edge servers. |
The current supported time units for cache duration are seconds, minutes, hours, days, with the default being hours.
When you choose Cache which means fixed cache duration or Follow Origin Cache Rules, you can additionally select Advanced Settings to customize the cache behavior based on origin response headers and client reload requests, which might have some default settings on the platform.
Parameter | Description |
---|---|
Ignore No-Cache Header From Origin | The default value of this option is No. For more details, see the introduction at the beginning of this document. If you choose Yes, all no-cache-related parameters in the origin response header, such as Cache-Control: no-cache , are ignored, and your current defined cache rule is applied directly. |
Ignore Authorization Header | The default value of this option is No. For more details, see the introduction at the beginning of this document. If you choose Yes, even requests carrying an Authorization header without Cache-Control: public in the origin response header can apply your current defined cache rule. |
Ignore Client Refresh | Set the handling rules for client reload requests. You can customize ignoring client reload request, which means the cached file on the CDN servers within the cache duration will be directly returned to the client, or you choose to convert it to if-modified-since which means if the files’ last modified time on the CDN edge servers is later than the client’s Last-Modified time, the cached file on the CDN edge servers is returned to the client; otherwise, a 304 Not Modified status is returned. |
Ignore Case Sensitivity
If you choose Yes, it means that the Effective Range you specify above will ignore letter case, two requests with URL differences only in letter case will both match the rule you set. For example, if you configure http://domain/a.jpg
for 1-hour caching, both http://domain/a.jpg
and http://domain/A.jpg
will be cached for 1 hour on CDN edge servers.
Conversely, if you choose No, case differences with settings in Effective Range will not be ignored in coming requests, and only requests matching the case exactly as specified in the Effective Range will be cached on CDN edge servers.
The default for this setting is Yes.
Priority
In the Priority field, you could specify the priority level of this rule. Based on the user’s request, the system matches the rules you have set. If multiple rules apply, the rule with the higher priority will be applied first.
Besides clicking the Add button to enter the detailed configuration page, you can also use the Quick Configuration button next to Add for a simplified cache rule configuration. The effective range will default to all requests, and you can choose either Cache or Follow Origin Cache Rules for cache duration, but Advanced Settings options are not available here. You can also directly select Do Not Cache and quickly set the apply priority of this simple rule.
After you have completed setting the configurations, please click OK and then select Next to submit your settings. To minimize any potential disruptions to your production environment, we strongly recommend conducting a Pre-deploy test in a staging environment. This crucial step ensures that your configurations are accurate before they go live. Once you have verified the accuracy of the settings, click Deploy Now to implement them in the live environment. The configurations typically become effective within 3-5 minutes. For comprehensive guidance on pre-deployment testing and to verify the effectiveness of your configurations, please consult the tutorial Deploy the Configurations to Staging Environment for Validation.
Example 1: Applying a Fixed Cache Duration for Specific File Types Requested by a Specific User Agent
For the associated domain under this rule, when the file type is png;jpeg
and the User-Agent is Mozilla/4.0
, the files will have a fixed cache duration of 6 hours on the CDN edge servers. The rule also forces ignoring no-cache parameters in the origin response headers, authorization headers in the request, and client reload requests.
The cache rules configured in this tutorial are effective on CDN servers. Different CDN solutions, such as Content Acceleration and Media Acceleration Live Broadcast, may apply different default cache rules for the same file types. The default rules provided here are for general reference. If the default rules are crucial for your website, please contact technical support for confirmation.