Help Center/ Content Delivery Network/ Troubleshooting/ Why Does the Configured Cache Rule Not Take Effect?
Updated on 2024-06-06 GMT+08:00

Why Does the Configured Cache Rule Not Take Effect?

Symptom

A cache rule has been set for JPG files with a cache TTL of 90 days. After image 1.jpg is prefetched, a client accesses image 1.jpg and finds that the cache is not hit.

Possible Causes and Countermeasures

  1. It takes about 5 minutes for the cache rule to take effect. Prefetch the resource after the rule takes effect and check whether the cache is hit.
  1. The cache TTL is too short, causing frequent origin pull. Set a proper cache TTL. For details, see Setting the Cache TTL.
    Figure 1 Short cache TTL
  2. Cache rules have priorities. The cache rule with a higher priority (large value) is matched first. Check the priority of your cache rules.

    Example: Assumed that you configured a File type cache rule for domain name www.example.com to cache JPG files for only one day. The priority of the cache rule is set to 2.

    Figure 2 Cache rule settings

    Result: When a user accesses the www.example.com/test/cdn.jpg file, two cache rules, Full path and File type, can be applied to this file. The priority of the Full path rule is 3, which is higher than that of the File type rule. Therefore, the system follows the Full path rule /test/*.jpg and caches the file for 3 seconds.

    Method: To make the File type rule to take effect, set its priority to a value greater than 3.

  3. If Origin Cache Control is enabled for the cache rule of JPG files and no-cache, private, or no-store is set on the origin server, CDN does not cache resources from the origin server. It pulls content from the origin server for each user request. In this case, disable Origin Cache Control.