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 with query string parameters;
- caching content with cookies.
Configure caching time
Cache time is the period during which CDN servers store 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, in the top menu, click Products and select CDN.
-
In the CDN resources section, open the CDN resource page → Caching.
-
Select the Enable cache 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
-
If you want to override the content source settings with your own, select the Ignore cache control headers checkbox. CDN will ignore the
Cache-ControlandExpiresheaders, which contain caching information and which the content source may include in the response. -
Click Apply. While the settings are being applied, the CDN resource will be in the
PROCESSINGstatus. Other settings cannot be applied at this time. The settings will take effect when the CDN resource enters theACTIVEstatus.
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, in the top menu, click Products and select CDN.
-
In the CDN resources section, open the CDN resource page → Caching.
-
Select the Enable cache settings checkbox.
-
In the Latest version of cached content (Use Stale) block, select the Serve the latest version of cached content if the source is unavailable checkbox.
-
In the When to serve the latest version of cached content field, select the errors upon which the last cached content should be served:
error— server connection error;timeout— timeout during server connection;invalid_header— server returned an empty or invalid response;updating— use of outdated cached response while cache files are being updated;http_500— internal server error;http_502— failure in data transmission between server and user;http_503— server cannot process the request;http_504— timeout during server connection;http_403— access error;http_404— CDN resource not found;http_429— too many requests.
-
Click Apply. While the settings are being applied, the CDN resource will be in the
PROCESSINGstatus. Other settings cannot be applied at this time. The settings will take effect when the CDN resource enters theACTIVEstatus.
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, in the top menu, click Products and select CDN.
-
In the CDN resources section, open the CDN resource page → Caching.
-
Select the Enable cache settings checkbox.
-
In the Cache with query string block, select the Cache with query string checkbox. By default, all request parameters will be taken into account.
-
If you want to take specific parameters into account in the request, clear the Include all parameters checkbox.
-
Enter the query parameter. You can enter an allowed or forbidden parameter:
-
to specify an allowed parameter, enable White List, add the parameter, and click . When processing the request, only parameters included in this list will be taken into account.
-
to specify a disallowed parameter, enable Black List, add the parameter, and click . When processing the request, all parameters not included in this list will be taken into account.
-
-
To add another query parameter, repeat step 6.
-
Click Apply. While the settings are being applied, the CDN resource will be in the
PROCESSINGstatus. Other settings cannot be applied at this time. The settings will take effect when the CDN resource enters theACTIVEstatus.
Cache content by cookies
By default, the CDN ignores cookies.
You can enable content caching based on cookie parameters.
The CDN caches one file with different cookies from the HTTP request header as distinct files, and every new user request is forwarded to the origin.
-
In the Control panel, in the top menu, click Products and select CDN.
-
In the CDN resources section, open the CDN resource page → Caching.
-
Select the Enable cache settings checkbox.
-
In the Cache with cookies block, select the Cache with cookies checkbox. By default, all cookies will be taken into account.
-
If you want to take specific cookies into account in the request, clear the Include all parameters checkbox.
-
Enter the cookie parameter. You can enter an allowed or forbidden parameter:
-
to enter an allowed cookie parameter, enable White List, add the allowed parameter, and click . When processing the request, only cookie parameters included in this list will be taken into account;
-
to enter a disallowed cookie parameter, enable Black List, add the disallowed parameter, and click . When processing the request, all parameters not included in this list will be taken into account.
-
-
To add another cookie parameter, repeat step 6.
-
Click Apply. While the settings are being applied, the CDN resource will be in the
PROCESSINGstatus. Other settings cannot be applied at this time. The settings will take effect when the CDN resource enters theACTIVEstatus.