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.
- 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.
- 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.
- Log on to the DCDN console.
- In the left-side navigation pane, click Domain Names.
- On the Domain Names page, find the domain name that you want to manage, and click Configure in the Actions column.
- In the left-side navigation pane on the details page of the specified domain, click Caching.
- On the Cache Duration tab, click Add.
- In the Cache Duration dialog box, select Directory or Filename Extension for the Type parameter and specify
the other parameters for the cache 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.
- 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
For example, if you set the following rules for
- 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.
example.aliyun.com, Rule 1 takes priority over the other two rules.
The following table describes the recommended TTL values for different types of cached files.
- 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.
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 filesNote 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
- Click OK.
After the cache expiration rule is created, click Modify or Delete to manage the rule.