When Alibaba Cloud Content Delivery Network (CDN) accelerates static resource delivery, it loads resources from an origin server to the CDN node that is closest to the visitor. When the visitor accesses the static resources, CDN retrieves the resources from the CDN node instead of the origin server. This reduces the resource delivery time because retrieving resources from the origin server is time-consuming.

How to calculate the TTL for a cached object

  • t = (Current time - Last-Modified) × 0.1
  • t = max(10, t)
  • t = min(t, 3600)

The time-to-live (TTL) is represented by t and measured in seconds.

Default caching rules

  • If the Last-Modified value of an object is 20140801 00:00:00 and the current time is 20140801 00:01:00, t = (Current time - Last-Modified) × 0.1 = 6 seconds. According to the calculation rules, the TTL is 10 seconds because the minimum value is 10 seconds.
  • If the Last-Modified value of an object is 20140801 00:00:00 and the current time is 20140802 00:00:00, t = (Current time - Last-Modified) × 0.1 = 8,640 seconds. According to the calculation rules, the TTL is 3,600 seconds because the maximum value is 3,600 seconds.
  • If the Last-Modified value of an object is 20140801 00:00:00 and the current time is 20140801 00:10:00, t = (Current time - Last-Modified) × 0.1 = 60 seconds. According to the calculation rules, the TTL is 60 seconds.
  • If the response from the origin server does not contain the Last-Modified header but contains the ETag header, the accessed object is more likely a static resource. The default TTL for this object is set to the minimum value that is configured by using the dft_expires directive.
  • If the response from the origin server does not contain the Last-Modified or the ETag header, the accessed object is a dynamic resource. The default TTL for this object is set to zero. The object will be retrieved from the origin server each time when it is requested.
Note

Website developers and related IT engineers are more familiar with the business logic of, and the static and dynamic content on their websites. We recommend that you set the TTL values in the console based on the file type and directory. For more information, see Create a cache expiration rule.

References

CDN supports the following cache functions.
Function Description
Create a cache expiration rule Allows you to configure cache expiration rules for static resources in a specified directory or with specified file extensions. In each cache expiration rule, you can set the TTL of the cached static resources and the priority. Based on these cache expiration rules, CDN caches the specified static resources on CDN nodes.
Create a status code expiration rule Allows you to configure expiration rules for HTTP status codes that are returned for resources in a specified directory or with specified file extensions.
Create an HTTP header Allows you to customize HTTP response headers.
Customize an error page Allows you to customize an error page for a specific HTTP or HTTPS status code.
Configure a rewrite rule Allows you to redirect request URIs to specified URIs by using 302 redirects.