All Products
Search
Document Center

Set cache expiration time

Last Updated: Dec 11, 2018

Introduction

  • This feature can be used to set the behavior of the cache server for resources that have different directory paths and filename extensions. You can set the cache duration for resource content.

  • You can customize a caching rule priority.

  • Default caching rules for the cache.

    • If an origin site has been configured with a caching rule, the cache duration configuration has higher priority than the origin configuration.

    • If no caching rules are configured for the origin site, you can set a caching rule by specifying the directory paths and filename extensions. You can set a full-path caching rule.

    The following figure shows the default caching rules:rule

Note: CDN cached files can be removed from the CDN node if the cached files are not updated frequently.

Recommendations

File type Cache DURATION Example
Infrequently updated static files 1 month or more Image type and application download type
Frequently updated static files Slightly shorter than 1 month .js, .css
Dynamic files Shorter cache duration Updated content of PHP files
Frequently updated dynamic files 0, indicating that this file type is not cached .php, .jsp, .asp, and so on
  • We recommend that the content on an origin site is updated with the same file name, but tagged with different version numbers. For example, use the img-v1.0.jpg and img-v2.1.jpg naming methods.

Procedure

  1. On the Domain Names page, select a domain name, and click Configure.

  2. Go to Caching > Cache Duration. You can add, modify, and delete the caching rules.

    99

  3. Click Add to add a caching rule. You can select Directory or Filename Extension.

  4. Example: Configure three caching rules for DCDN domain name example.aliyun.com:

    • Caching rule 1: All resources with the jpg or png filename extension expire in one month and the weight is set to 90.

    • Caching rule 2: The directory is /www/dir/aaa. The expiration time is one hour and the weight is set to 70.

    • Caching rule 3: The full path is /www/dir/aaa/example.php. The expiration time is zero seconds and the weight is set to 80.

    The priority is Rule 1 > Rule 3 > Rule 2.

    Note:

    • The value range of weight is from 1 to 99. The larger the value, the higher the priority.
    • We recommend that you do not set the same weight for different caching rules. Caching rules with the same weight will be assigned a random priority.