All Products
Search
Document Center

:How do I specify a TTL value for POPs when I use Alibaba Cloud CDN to accelerate the delivery of static content?

Last Updated:Feb 29, 2024

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.

WebServer cache policy settings

Alibaba Cloud CDN default cache policy

Important
  • 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.

      Note

      t: 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.

      1. Calculate the value of t1.

        t1 = (Curtime - Last_Modified) * 0.1
      2. Compare the value of t1 calculated in the previous step with 10, and use the larger value as t2.

        t2 = max(10,t1)
      3. 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 is 20140801 00:00:00 and Curtime is 20140801 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 is 20140801 00:00:00 and Curtime is 20140802 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 is 20140801 00:00:00 and Curtime is 20140801 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 the ETag 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 the dft_expires directive to configure the minimum value.

  • If the response from the origin server does not contain the Last-Modified or the ETag 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.