Configure content caching
By default, content caching settings are turned off. You can turn them on and customize them:
- cache time;
- giving content from the cache in case of source errors;
- content caching taking into account the request parameters;
- Cookie-aware content caching.
Configure cache time
Cache time is the time CDN servers keep a copy of the response from the source until the content is requested again. Cache 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 - storage time of successful responses;
- 3xx - redirect storage time;
- 4xx - client error storage time;
- 5xx - server error storage time;
- in the browser - the time for which the browser can cache the response after it is received from the CDN.
-
If you want to override the content source's settings to your own, check the Ignore Cache Control Headers checkbox. The CDN will ignore
Cache-ControlandExpiresheaders that contain caching information that the content source may include in the response. -
Click Apply. The resource will be in
PROCESSINGstatus while the settings are being applied . You cannot apply any other settings at this time. The settings will be applied when the share changes toACTIVEstatus.
Retrieve content from cache on source errors
If the content source responds with an error, the user can get the latest cached version of the content (Use Stale). While the source is unavailable, pages of the site may not be displayed completely: for example, not all images, videos or stylesheets may work. In this case, CDN servers will check its availability with each new request:
- if the error persists, CDN servers will give the last cached content with the
Cache: Staleheader; - If the source is restored, the CDN will cache the latest version of the file.
To give content from the cache when source errors occur:
-
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 Last Version of Cached Content (Use Stale) box, select the Give the latest version of cached content if the source is unavailable checkbox.
-
In the When to give the latest version of cached content: list, select the errors when you want to give the latest cached content:
error(server connection error)timeout(time exceeded while connecting to the server)invalid_header(the server returned an empty or invalid response)updating(using an outdated cached response while the files in the cache are being updated)http_500(internal server error)http_502(failure in data transfer between server and user)http_503(server cannot process the request)http_504(time exceeded while connecting to the server)http_403(access error)http_404(resource not found)http_429(too many requests)
-
Click Apply. The resource will be in
PROCESSINGstatus while the settings are being applied . You cannot apply any other settings at this time. The settings will be applied when the share changes toACTIVEstatus.
Cache content based on request parameters
By default, the CDN ignores the query string parameters.
You can enable content caching based on the request parameters.
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 tab.
-
Check the Enable caching settings checkbox.
-
In the Cache for query string box, check the Cache for query string checkbox . By default, all query parameters will be taken into account.
-
If you want to consider certain parameters in the query, uncheck the Consider all parameters checkbox.
-
Specify the allowed or disallowed query parameters:
-
enable White List, add an allowed parameter, and click . Only parameters that are included in this list will be considered when processing the request.
-
or enable Black List, add the disallowed parameter, and click . All parameters that are not included in this list will be taken into account when processing the request.
-
-
Click Apply. The resource will be in
PROCESSINGstatus while the settings are being applied . You cannot apply any other settings at this time. The settings will be applied when the share changes toACTIVEstatus.
Cache content with cookies
By default, the CDN ignores cookies.
You can enable caching of content based on cookie settings.
The CDN caches a single 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 tab.
-
Check the Enable caching settings checkbox.
-
In the Cache with cookies box, check the Cache with cookies checkbox . By default, all cookies will be taken into account.
-
If you want to consider certain cookies in the request, uncheck the Consider all parameters checkbox.
-
Specify whether you want to allow or disallow cookies:
-
enable the White List, add an allowed cookie setting, and click . Only cookies that are included in this list will be considered when processing the request.
-
or enable Black List, add the disallowed cookie parameter, and then click . All parameters that are not included in this list will be taken into account when processing the request.
-
-
Click Apply. The resource will be in
PROCESSINGstatus while the settings are being applied . You cannot apply any other settings at this time. The settings will be applied when the share changes toACTIVEstatus.