Dynamic Route for CDN (DCDN) allows you to create cache expiration rules for 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 cache policy and how to create a cache expiration rule.

Background information

A cache server caches resources of specified file types or in specified directories based on the specified cache policy. You can set the TTL value in a cache expiration rule to specify the time period for which the resources are cached.
  • You can customize the priority of each cache policy.
  • By default, cache policies are applied based on the following rules:
    • If a cache rule is configured for an origin server, the specified cache expiration rule takes priority over the cache rule for the origin server.
    • If no cache rules are configured for an origin server, you can set cache expiration rules by directory or file extension. Full paths are supported for cache policies.
The following figure shows how cache policies are applied to resources on DCDN nodes.Caching policy
Note
  • You can set cache expiration rules in a cache policy to specify the expiration time of files. The specified cache expiration rule takes priority over the cache rule for the origin server. If no cache rule is configured for the origin server, you can set a cache rule by directory or by file extension.
  • A DCDN node may remove the cached files that are not frequently updated on the node before the files expire.

Procedure

  1. Log on to the DCDN console.
  2. In the left-side navigation pane, click Domain Names.
  3. On the Domain Names page, find the domain name that you want to manage, and click Configure in the Actions column.
  4. In the left-side navigation pane on the details page of the specified domain, click Caching.
  5. On the Cache Duration tab, click Add.
  6. In the Cache Duration dialog box, select Directory or Filename Extension for the Type parameter and specify the other parameters for the cache rule.
    Create a cache expiration rule
    Parameter Description
    Type
    • Directory: specifies the resources cached in the specified directory.
    • Filename Extension: specifies the resources that are cached in files with the specified file extensions.
    Content
    • If you select Directory, enter a directory name in the Content field. The directory name must start with a forward slash (/), such as /directory/aaa.
    • If you select Filename Extension, enter one or more file extensions in the Content field. Separate multiple file extensions with commas (,), such as JPG,TXT.
      The following static file types are supported:
      • Images: GIF, PNG, BMP, JPEG, and JPG.
      • Web pages: HTML, HTM, and SHTML.
      • Audio and video files: MP3, WMA, FLV, MP4, WMV, OGG, and AVI.
      • Text files: DOC, DOCX, XLS, XLSX, PPT, PPTX, TXT, and PDF.
      • Others: ZIP, EXE, TAT, ICO, CSS, JS, SWF, APK, M3U8, and TS.
    Expire In Set a TTL value for the cached resources. A DCDN node can retain the cached resources for up to three years. We recommend that you set this parameter based on the following rules:
    • Specify a TTL value of one month or longer for static files that are not frequently updated, such as images and packages for application downloads.
    • Specify a TTL value based on your actual workloads for static files that are frequently updated, such as JS and CSS files.
    • We recommend that you specify a TTL value of 0 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 that ranges from 1 to 99. A higher value indicates a higher priority. Rules with higher priorities take precedence over rules with lower priorities.
    • We recommend that you set different priorities for different rules. If different rules have the same priority, one of these rules is randomly applied.
    For example, if you set the following rules for example.aliyun.com, Rule 1 takes priority over the other two rules.
    • Rule 1: Filename Extension is selected for Type, Content is set to jpg,png, Expire In is set to 1 month, and Weight is set to 90.
    • Rule 2: Directory is selected for Type, Content is set to /www/dir/aaa, Expire In is set to 1 hour, and Weight is set to 70.
    • Rule 3: Directory is selected for Type, Content is set to /www/dir/aaa/example.php, Expire In is set to zero seconds, and Weight is set to 80.
    The following table describes the recommended TTL values for different types of cached files.
    File type TTL value Example
    Static files that are infrequently updated One month or more Images and packages for application downloads
    Static files that are frequently updated Less than one month JS and CSS files
    Dynamic files 1s PHP files that contain dynamic content
    Dynamic files that are frequently updated 0 seconds (The specified files are not cached.) PHP, JSP, and ASP files
    Note When you update a resource file on the origin server, we recommend that you include the version number in the name of the file that you want to update to avoid duplicate file names. For example, you can specify the names of two updated files as img-v1.0.jpg and img-v2.1.jpg.
  7. Click OK.

    After the cache expiration rule is created, click Modify or Delete to manage the rule.