Alibaba Cloud CDN accelerates the delivery of static content by caching the content from an origin server to the available points of presence (POPs) that are nearest to the clients. Then, the static content is accessed and obtained from the POPs. This topic describes how to specify a time-to-live (TTL) value for POPs.
Description
You can specify a TTL value by applying console settings, origin header settings, and default cache policy settings. The settings are in descending order of priority.
For more information about console settings, see Create a cache rule for resources.
For more information about origin header settings, see WebServer cache policy settings.
The default cache policy is a global policy that is used when you do not specify a TTL value in the console or on the origin server. This ensures the acceleration performance and prevents issues caused by dynamic file caching. For more information about default cache policy settings, see Alibaba Cloud CDN default cache policy.
NoteFor more information about Object Storage Service (OSS) cache policy settings, see Manage object metadata.
WebServer cache policy settings
For information about how to configure an NGINX cache policy, see Configure an NGINX cache policy.
For information about how to configure an Apache cache policy, see Configure an Apache cache policy.
For information about how to configure an Internet Information Services (IIS) cache policy, see Configure an IIS cache policy.
Alibaba Cloud CDN default cache policy
Website developers and technical engineers have a better understanding of the business logic and static and dynamic factors of their websites. We recommend that you specify a TTL value in the Alibaba Cloud CDN console based on the file type and directory. For more information, see Create a cache rule for resources.
If you have configured a cache policy, the default cache policy does not take effect.
By default, POPs calculate the default TTL value based on formulas. This section describes the formulas for calculating the default TTL value and provides examples for ease of understanding.
To calculate the TTL value, perform the following steps.
Notet: the TTL value, in seconds. Curtime: the current time. Last_Modified: the value of the Last-Modified header in the response from the origin server.
Calculate the value of t1.
t1 = (Curtime - Last_Modified) * 0.1
Compare the value of t1 calculated in the previous step with 10, and use the larger value as t2.
t2 = max(10,t1)
Compare the value of t2 calculated in the previous step with 3,600, and use the smaller value as t, which is the TTL value.
t = min(t2,3600)
Examples:
If the
Last-Modified
value of an object is20140801 00:00:00
and Curtime is20140801 00:10:00
, t1, t2, and t are calculated by using the following formulas: t1 = (Curtime - Last_modified) × 0.1 = 60, t2 = max(10, t1) = 60, and t = min(t2, 3600) = 60. Therefore, the TTL value is 60 seconds.If the
Last-Modified
value of an object is20140801 00:00:00
and Curtime is20140802 00:00:00
, t1, t2, and t are calculated based on the following formulas: t1 = (Curtime - Last_modified) × 0.1 = 8,640, t2 = max(10, t1) = 8,640, and t = min(t2, 3600) = 3,600. Therefore, the TTL value is 3,600 seconds.If the
Last-Modified
value of an object is20140801 00:00:00
and Curtime is20140801 00:01:00
, t1, t2, and t are calculated based on the following formulas: t1 = (Curtime - Last_modified) × 0.1 = 6, t2 = max(10, t1) = 10, and t = min(t2, 3600) = 10. Therefore, the TTL value is 10 seconds.
If the response from the origin server does not contain the
Last-Modified
header but contains theETag
header, the retrieved object is more likely a static resource. The default TTL value for this object is set to the minimum value. You can use thedft_expires
directive to configure the minimum value.If the response from the origin server does not contain the
Last-Modified
or theETag
header, the retrieved object is a dynamic resource. The default TTL value for this object is set to 0. The object is retrieved from the origin server each time the object is requested.