Configure content caching
By default, content caching settings are disabled. You can enable and configure them:
- caching time;
- serving content from cache on source errors;
- caching content by query string;
- caching content by cookies.
Configure caching time
Caching time is the time for which CDN servers hold a copy of a response from the source before requesting the content again. Caching time can be configured for each HTTP response.
-
In the control panel, on the top menu, click Products and select CDN.
-
In the CDN Resources section, open the CDN resource page → Caching tab.
-
Check the Enable caching settings checkbox.
-
In the Content caching time block, configure the caching time for each response type:
- for
2xx— retention time for successful responses; 3xx— retention time for redirects;4xx— retention time for client errors;5xx— retention time for server errors;- in browser — the time the browser can cache a response after receiving it from the CDN.
- for
-
To override the content source settings with your own, check the Ignore cache control headers checkbox. The CDN will ignore
Cache-ControlandExpiresheaders that contain caching information from the content source. -
Click Apply. While settings are being applied, the CDN resource enters the
PROCESSINGstatus. You cannot apply other settings during this time. Settings take effect when the CDN resource transitions toACTIVE.
Serve content from cache on source errors
If the content source returns an error, the user can receive the last cached version of the content (Use Stale). While the source is unavailable, site pages may not display correctly: for example, some images, videos, or stylesheets may not work. CDN servers will check the availability of the source with each new request:
- if the error persists, CDN servers will serve the last cached content with the
Cache: Staleheader; - if the source functionality is restored, the CDN server will cache the fresh version of the file.
To serve content from cache on source errors:
-
In the control panel, on the top menu, click Products and select CDN.
-
In the CDN Resources section, open the CDN resource page → Caching.
-
Check the Enable caching settings checkbox.
-
In the Last cached content version (Use Stale) block, check the Serve the last cached version if the source is unavailable.
-
In the Serve stale content on list, select the errors that should trigger serving the last cached content:
error— connection error to the server;timeout— connection timeout with the server;invalid_header— the server returned an empty or invalid response;updating— serve stale cached response while files in cache are being updated;http_500— internal server error;http_502— bad gateway error;http_503— server cannot process the request;http_504— gateway timeout;http_403— forbidden error;http_404— CDN resource not found;http_429— too many requests.
-
Click Apply. While settings are being applied, the CDN resource enters the
PROCESSINGstatus. You cannot apply other settings during this time. Settings take effect when the CDN resource transitions toACTIVE.
Cache content by query string
By default, the CDN ignores query strings (query string).
You can enable caching content by query string.
If requests to the same file contain different parameters (the part after the question mark in the file URL), each request with a new parameter is redirected to the source.
-
In the control panel, on the top menu, click Products and select CDN.
-
In the CDN Resources section, open the CDN resource page → Caching.
-
Check the Enable caching settings checkbox.
-
In the Cache by query string block, check the Cache by query string checkbox. By default, all query parameters will be considered.
-
If you want to consider specific request parameters, uncheck the Consider all parameters checkbox.
-
Specify allowed or forbidden query parameters:
-
enable White List, add an allowed parameter, and click . Only parameters in this list will be considered when processing requests.
-
or enable Black List, add a forbidden parameter, and click . All parameters not in this list will be considered when processing requests.
-
-
Click Apply. While settings are being applied, the CDN resource enters the
PROCESSINGstatus. You cannot apply other settings during this time. Settings take effect when the CDN resource transitions toACTIVE.
Cache content by cookies
By default, the CDN ignores cookies.
You can enable caching content by cookie parameters.
The CDN caches the same file with different cookies from the HTTP request header as different files, and each new user request is redirected to the source.
-
In the control panel, on the top menu, click Products and select CDN.
-
In the CDN Resources section, open the CDN resource page → Caching.
-
Check the Enable caching settings checkbox.
-
In the Cache by cookies block, check the Cache by cookies checkbox. By default, all cookies will be considered.
-
If you want to consider specific cookies in the request, uncheck the Consider all parameters checkbox.
-
Specify allowed or forbidden cookie parameters:
-
enable White List, add an allowed cookie parameter, and click . Only cookie parameters in this list will be considered when processing requests;
-
or enable Black List, add a forbidden cookie parameter, and click . All parameters not in this list will be considered when processing requests.
-
-
Click Apply. While settings are being applied, the CDN resource enters the
PROCESSINGstatus. You cannot apply other settings during this time. Settings take effect when the CDN resource transitions toACTIVE.