Dynamic Route for CDN (DCDN) allows you to create cache expiration rules to expire static resources of specified file types or in specified directories. Each cache expiration rule defines the time-to-live (TTL) value and the priority for the cached resources. When a static resource expires, the resource is automatically deleted from DCDN nodes. This topic describes the DCDN caching policy and how to create a cache expiration rule.

Background information

A cache server (DCDN node) caches resources of specified file types or in specified directories depending on the caching policy. You can set TTL values to specify how long the resources are cached in a cache expiration rule.
  • You can customize the priority of each cache expiration rule.
  • By default, the caching policies are applied as follows:
    • If the HTTP cache headers exist in the HTTP responses from the origin server, the cache expiration settings in the DCDN console override the origin-provided cache settings. However, the cache-control: no-cache directive will not be overridden.
    • If no HTTP cache headers exist in the HTTP responses from the origin header, the cache expiration settings in the console prevails. You can set cache expiration rules for resources in the specified directories or with the specified file extensions. Full paths are supported.
The following figure shows how the caching policies are applied to resources on DCDN nodes.Caching policy
Note
  • You can set cache expiration rules for resources in the specified directories or with the specified file extensions in the DCDN console. Full paths are supported. If the HTTP cache headers exist in the HTTP responses from the origin server, the cache expiration settings in the console override the origin-provided cache settings. However, the cache-control: no-cache directive will not be overridden. If no HTTP cache headers exist in the HTTP responses from the origin header, the cache expiration settings in the console prevails.
  • A DCDN node may remove the cached files that are not updated frequently on the node before they expire.

Procedure

  1. Log on to the Dynamic Route for CDN console.
  2. In the left-side navigation pane, click Domain Names.
  3. On the Domain Names page, find the target domain name and click Configure.
  4. In the left-side navigation pane of the specified domain, click Caching.
  5. Click the Cache Duration tab, and click Add.
  6. In the Cache Duration dialog box that appears, set Type to Directory or Filename Extension, and configure the other required parameters, as described in the following table.
    Parameter Description
    Type
    • Directory: specifies resources cached in the specified directory.
    • Filename Extension: specifies resources cached in files with the specified file extensions.
    Content
    • If you set Type to Directory, enter a directory name in the Content field. The directory name must start with a forward slash (/), for example, /directory/aaa.
    • If you set Type to Filename Extension, enter one or more file extensions in the Content field. Separate multiple file extensions with commas (,), for example, JPG,txt.
    Expire In Set a TTL value of the cached resources. A DCDN node can cache resources for up to three years. We recommend that you set this parameter according to the following rules:
    • Specify a TTL value of one month or longer for static files such as images and applications that are not frequently updated.
    • Specify a TTL value based on your actual workloads for static files such as JavaScript and CSS files that are frequently updated.
    • Specify a TTL value of zero seconds to disable caching for dynamic files such as PHP, JSP, and ASP files.
    Weight Set the priority of the cache expiration rule.
    Note
    • The value must be an integer from 1 to 99. A higher value indicates a higher priority and a rule with a higher priority prevails over rules with lower priorities.
    • We recommend that you do not set the same priority for different rules. If different rules have the same priority value, one of these rules is applied at random.
    For example, if you set the following rules for example.aliyun.com, Rule 1 is applied preferentially over the other two rules:
    • Rule 1: Type is set to Filename Extension, Content is set to jpg,png, Expire In is set to 1 month, and Weight is set to 90.
    • Rule 2: Type is set to Directory, Content is set to /www/dir/aaa, Expire In is set to 1 hour, and Weight is set to 70.
    • Rule 3: Type is set to Directory, Content is set to /www/dir/aaa/example.php, Expire In is set to zero seconds, and Weight is set to 80.
    Create a cache expiration rule
  7. Click OK.

    After the cache expiration rule is created, you can click Modify or Delete in the Actions column to modify or delete the rule.

Recommended configurations

The following table lists the recommended TTL values for different types of cached files.
File type TTL value Example
Static files that are infrequently updated At least one month Images and application download packages
Static files that are frequently updated Slightly shorter than one month JavaScript and CSS files
Dynamic files 1 second PHP files that have content updated
Dynamic files that are frequently updated 0 seconds, indicating that the specified files are not cached PHP, JSP, and ASP files
Note When you update a resource file on the origin, 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 updated files as img-v1.0.jpg and img-v2.1.jpg.