You can create cache expiration rules to define the time to live (TTL) value of static resources. You can also specify a priority for each cache expiration rule. This improves the cache hit rate of Content Delivery Network (CDN) nodes. After a resource expires, it is automatically deleted from the CDN node and re-cached on the CDN node from the origin server. This topic describes cache expiration rules for resources on CDN nodes and how to create a cache expiration rule.
Features
- If you have not set a cache expiration rule on your origin server or CDN nodes, the CDN nodes use the default TTL value of 3,600 seconds to expire cached resources. You can modify the TTL value after you add a domain name for CDN. The amount of back-to-origin traffic and the fees incurred vary based on the TTL value. We recommend that you set a TTL value based on your business requirements. A small TTL value may cause CDN nodes to frequently redirect requests to the origin server and increase the amount of network traffic that is consumed by the origin server.
- If an origin server has a cache expiration rule configured, the cache expiration rule on the CDN node has a higher priority than the cache expiration rule that is configured on the origin server. If an origin server has no cache expiration rule configured, you can set a cache expiration rule by directory or by file name extension. You can set a full-path cache expiration rule.
- A CDN node may remove the cached files before they expire if they are not frequently updated.
- If a client request carries the If-Match header and the response from the origin server carries the ETag header, the CDN node directly returns the requested resources to the client when the value of the If-Match header is the same as the value of the ETag header. When the value of the If-Match header is different from the value of the ETag header, the CDN node retrieves the latest version of the requested resource from the origin server and then returns it to the client. At the same time, the resources that are cached on the CDN node are replaced by the retrieved version. The matching rule between the If-Match header and the ETag header has a higher priority than the cache expiration rule that is configured on CDN nodes.
When you update a resource file on your origin server, we recommend that you include the version number in the name of the update file instead of using the same name as the existing resource file. For example, you can name two update files img-v1.0.jpg and img-v2.1.jpg. You can then set a cache expiration rule for the resource file. The following figure shows the cache expiration rule for resources on CDN nodes.
