You can set the cache validity period of resources on the origin server on CDN nodes in Node Cache Validity to adjust the cache update frequency of origin server resources on the CDN nodes. You can configure the resource cache validity period by directory, file extension, and full file path based on your business needs.
CDN will determine whether a resource cached on a CDN node expires based on the cache validity period configured in Node Cache Validity.
After a resource on the origin server is updated, its cache on the CDN node must be updated immediately. You can use the cache purge feature to update unexpired caches on the CDN node, so as to ensure that resources cached on the CDN node and stored on the origin server are consistent.
img-v1.jpg
and img-v2.jpg
, to prevent CDN nodes from returning the old but unexpired resource to the end user after the resource content is changed on the origin server.Cache-Control
response header to control the cache validity period on CDN nodes (when Cache Option is Follow Origin Server). Then, CDN nodes will pass the Cache-Control
header to the end user to control the browser cache validity period. If you want CDN nodes to set the browser cache validity period, you can modify the Cache-Control
header returned by CDN nodes to the user in Browser Cache Validity.Configuration Item | Description |
---|---|
Type | You can select All Files, File Extension, File Directory, Full Path, or Homepage. All Files: Set the rule for all files. This is the default option. File Extension: Set the rule for the specified file extension. File Directory: Set the rule for the specified file directory. Full Path: Set the rule for the specified full file path. Homepage: Set the rule for the specified domain name root directory. |
Content | Enter the content based on the selected file type. If Type is All Files, the content is fixed to all files. If Type is File Extension, you can enter one or multiple file extensions separated by ";", such as `jpg;png;css`. If Type is File Directory, you can enter one or multiple file directories separated by ";", and the entered content cannot end with "/", such as `/test;/a/b/c`. If Type is Full Path, you can enter one or multiple full file paths separated by ";", such as `/index.html;/test/.jpg`. |
Cache Option | You can select Follow Origin Server, Cache, or Do not cache. Follow Origin Server: The CDN node cache validity period will be set based on the `Cache-Control` origin server header, and heuristic caching can be enabled. Cache: You can customize the CDN node cache validity period and enable force cache. Do not cache: CDN nodes will not cache any resources. |
The cache validity period will be set on CDN nodes based on the Cache-Control
origin server response header.
Cache-Control
origin server response header is max-age
, the CDN node cache validity period will be set based on the value of max-age
. For example, if Cache-Control: max-age=300
is configured, the cache validity period will be 300 seconds.Cache-Control
origin server response header is no-cache
, no-store
, or private
, the CDN node will not cache resources.Cache-Control
or Expires
origin server response header, the cache rule will be set based on the heuristic caching status:Cache-Control
or Expires
origin server response header, the cache validity period will be 600 seconds.Cache-Control
or Expires
origin server response header, the heuristic cache validity period will be set according to the following rules:Last-Modified
origin server response header, the cache validity period will be calculated as follows: (current time - Last-Modified
) * 0.1. If there is no Last-Modified
origin server response header, the cache validity period will be 600 seconds by default.You can customize the cache validity period on the CDN node.
Cache-Control
origin server response header is max-age
or there is no Cache-Control
header, resources will be cached according to the custom CDN node cache rule.Cache-Control
origin server response header is no-cache
, no-store
, or private
, CDN nodes will not cache resources.Cache-Control
origin server response header will be ignored, and resources will be cached according to the custom CDN node cache rule.CDN nodes are configured to not to cache resources. For each user request to access a resource, CDN nodes will directly perform origin-pull to get the resource and return it to the user.
If multiple cache rules are configured, the lower the rule position, the higher the priority. You can click Adjust Priority to drag and drop cache rules to change their order and adjust the priority.
For seldom updated static files, such as images and large files, we recommend you set the cache validity period to 30 days.
For frequently updated static files, such as .js and .css files, we recommend you set the cache validity period based on the update frequency of your business.
For dynamic files, such as .php, .jsp, .asp, and .aspx files, you need to set Cache Option to Do not cache.
For other requests involving direct interaction with the origin server, such as site login (/wp-admin
directory for WordPress backend login, for example) or API-based query, you need to set Cache Option to Do not cache; otherwise, an access error may occur.
You can add up to 100 cache rules for a domain name.
If there are multiple cache rules, the lower the rule position, the higher the priority.
If Type is set to File Extension, File Directory, or Full Path, you can enter up to 100 items and separate them by ";", such as jpg;png
(when Type is set to File Extension).
If no rules are configured or the request fails to hit any configured rules, the cache validity period will be set on CDN nodes based on the Cache-Control
origin server response header. If there is no Cache-Control
header, CDN nodes will cache the resource for 600 seconds.
CDN nodes only cache content requested by GET and HEAD requests. Content requested by POST and OPTIONS requests won't be cached on CDN nodes.
The original cache rules specify that CDN doesn't cache .php, .jsp, .asp, and .aspx files and caches other files for 30 days.
You need to add a rule to cache .jpg and .png files for 10 days while ignoring the Cache-Control
origin server response header (i.e., enabling force cache), and change Cache Option in the cache rule for All Files to Follow Origin Server.
Click Add Rule, set Type to File Extension, Content to jpg;png
, Cache Option to Cache, Cache Validity to 10 days, and Force Cache to Yes, and click OK.
Select the cache rule for All Files, click Modify, change Cache Option to Follow Origin Server, and click OK.
After the adjustment, the cache rules are:
.jpg and .png files will be cached for 10 days with force cache enabled.
.php, .jsp, .asp, and .aspx won't be cached.
Other files will be cached for 30 days.
The www.test.com/abc.jpg
resource will be cached on the node for 10 days, even though the field in the Cache-Control
origin server response header is no-cache
, no-store
, or private
.
The www.test.com/def.php
resource won't be cached to the node.
Suggestions on configuring node cache validity rules for a site built based on WordPress:
/wp-admin
directory for backend login, you need to set Cache Option to Do not cache; otherwise, backend login resources will be cached and login errors will occur. If there are any API resources, you also need to set Cache Option to Do not cache for them.Add cache rules while retaining the default CDN cache rules:
/wp-admin
, and Cache Option to Do not cache, and click OK.html;js;css
, Cache Option to Cache, Cache Validity to 7 days, and Force Cache to No, and click OK./wp-admin
directory to the bottom to grant it the highest priority./wp-admin
directory will not be cached.
Was this page helpful?