Set Cache Rules

Last update:2026-04-27 09:42:37

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.

Default Cache Rules Based on Headers

  • If the origin server’s response header includes parameters indicating no-cache, such as 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.
  • If the origin server’s response header does not include the aforementioned no-cache parameters, or includes an 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).

CDNetworks has a default cache strategy and cache TTL based on different request file types or request types. Please go to Default Caching Strategy for details.

How to Set Cache Rules

  1. Log in to the CDNetworks Console and select the appropriate product.
  2. 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 image.png.
  3. Enter the configuration modification page, find the Cache Rules under Cache Optimization, and click the Add button;
  4. On the rule editing page, you can easily add the following configuration options based on your needs.

Apply to
On the CDNetworks CDN platform, you can specify the scope that your custom cache rules apply to by choosing from the following options:

Options Description
All Requests Indicates that all requests initiated to 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/.
Specific File Type 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.
Specific URL Path You can set specific URIs for this cache rule, supporting Full URL Path or Ignore Query String. Multiple URIs can be separated by line breaks.
Full URL Path: The user’s requested URI must fully match the configured URI for this rule to take effect.
Ignore Query String: 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, and 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.
Specific Directory This rule applies to all requests aimed at specified directories. 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/, indicating that the rule applies to requests for the directory http://domain/file/1%1/ and all files within it.
Please note that, you need to separate multiple directories with a line break.
URL Pattern (Regex) 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.

Advanced Scope Conditions

In addition to selecting the scope of your custom cache rule from the above list, you can make some more configuration in Advanced Scope Conditions. This works in conjunction with the Apply to you set, forming the actual scope of the cache rule under an AND relationship. The Advanced Scope Conditions offers the following options:

Parameter Description
UA or Exclude User-Agent 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.
Exclude 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 Pattern configuration item above.

Cache Behavior
For requests that match your defined rules, you can configure the cache behaviors on CDN servers within the CDNetworks platform. You have three caching behaviors to choose from:

Parameter Description
Cache TTL This option allows you to set a fixed Time-To-Live (TTL) for matched content. Using a fixed TTL is advisable when your assets follow a predictable update schedule, which helps improve CDN cache efficiency and reduce back-to-origin traffic.
Respect Origin Cache Headers 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’s 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.

Case-Insensitive Match
The default setting is Yes.

  • If you choose Yes, it means that the Apply to 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 Apply to will not be ignored in coming requests, and only requests matching the case exactly as specified in the Apply to will be cached on CDN edge servers.

Advanced Settings
When you select either the Cache TTL or the Respect Origin Cache Headers configuration, 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 Origin No-Cache Headers 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.
Client Reload Handling 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 Convert to IMS Request 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.
Cache with 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, requests carrying an Authorization header without Cache-Control: public in the origin response header can apply your current defined cache rule.

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 Settings button next to Add for a simplified cache rule configuration. The rule applied scope will default to all requests, and you can choose either Cache TTL or Respect Origin Cache Headers 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, 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.

Best Practices

Example 1: Applying a Fixed Cache TTL 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.

Notes
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.

Is the content of this document helpful to you?
Yes
I have suggestion
Submitted successfully! Thank you very much for your feedback, we will continue to strive to do better!