Problem description
When you use Alibaba Cloud CDN to accelerate static resources, CDN caches the resources on the source station to the CDN node closest to the client. After configuring the Alibaba Cloud Content Delivery Network cache, when viewing the detailed request and returned message information, it is found that the cache cannot be hit.
Possible causes
The Alibaba Cloud Content Delivery Network cache cannot be hit for the following reasons:
- Client requests are dynamic requests
- The origin server returns an HTTP header that is forcibly not cached.
- The response header ETag and Last-modified are not returned.
- Static acceleration is not configured for Dynamic Route for CDN
Solution
If you cannot hit the Alibaba Cloud Content Delivery Network cache when you are using the cache configuration of Alibaba Cloud Content Delivery Network acceleration, troubleshoot the problem based on the cause of the problem. See the following operations:
- The client request is a dynamic request
. If the request is a dynamic request, the Alibaba Cloud Content Delivery Network cache cannot be hit. When the client accesses these dynamic contents, it needs to access the user's server every time. The server dynamically generates real-time data and returns it to the client. - The origin returns HTTP headers
that are not forced to be cached When the origin is configured with the following response headers, the Alibaba Cloud Content Delivery Network does not cache the resource even if the caching rules are configured because these response headers have a higher priority in the Alibaba Cloud Content Delivery Network caching rules.- Any one of s-maxage=0, max-age=0, no-cache, no-store, and private
As shown in the following figure, the origin server responds to no-cache and private, and the Alibaba Cloud Content Delivery Network cannot be cached. The X-Cache field is MISS and the X-Swift-CacheTime is 0. In this case, you must delete the HTTP response header from the origin server. For more information, see Nginx cache policy settings, Apache cache policy settings, IIS cache policy settings.
- s-maxage or s-maxage=0
- Pragma: no-cache
- Any one of s-maxage=0, max-age=0, no-cache, no-store, and private
- The response header ETag and Last-modified
are not returned. If the Alibaba Cloud Content Delivery Network does not have cache rules configured, the static file cannot be cached on the Alibaba Cloud Content Delivery Network node if the response header ETag and Last-modified are not returned. You can configure ETag and Last-modified on the origin server, or configure cache rules directly on the Alibaba Cloud Content Delivery Network. For more information about how to configure cache rules, see Configure cache expiration time. - Dynamic Route for CDN static acceleration
is not configured, the default Dynamic Route for CDN is dynamic acceleration. Dynamic acceleration is returned to the origin every time. To cache, you must configure static acceleration. For more information about how to configure static acceleration, see Configure static acceleration. Currently, you can configure static acceleration based on the file type, URI, and path. If static acceleration is not configured for the Dynamic Route for CDN, it is dynamic acceleration. The HTTP header of the Dynamic Route for CDN node response does not have fields such as X-Cache and X-Swift-CacheTime, similar to the following:
References
- How to use the browser's review element to determine whether the Alibaba Cloud Content Delivery Network cache is successful
- URL's passing parameter is variable, resulting in low Alibaba Cloud Content Delivery Network cache hit rate
- What are the factors that affect the Alibaba Cloud Content Delivery Network cache hit rate?
- Alibaba Cloud Content Delivery Network Cache Hit Rate Low Troubleshooting Method
Applicable scope
- CDN