Why is my CloudFront distribution returning an “X-Cache:Miss from CloudFront” response?
Last updated: 2022-01-29
I configured my Amazon CloudFront distribution and origin to cache objects, but my distribution is returning an "X-Cache:Miss from CloudFront" response. Why is this happening? What can I do to avoid this response?
To diagnose and troubleshoot a "X-Cache:Miss from CloudFront" response, check the following:
Which edge location is receiving the requests?
After an object is requested through CloudFront, the object is cached only in the edge location that received the request. If a subsequent request is made to another edge location, the other edge location won't have a cached version of the object. This scenario returns an "X-Cache:Miss from CloudFront" response.
To determine if the response is coming from one edge location or from multiple edge locations, send several requests from the same client to the same object. Then, check the IP addresses that the connection is established on. Run a reverse DNS lookup on the IP addresses to determine which edge location the requests are going to.
You can also determine the edge location by checking the value of the "x-amz-cf-pop" response header after making a request to your CloudFront distribution.
How frequently is the object requested?
If an object in an edge location isn't requested frequently, then CloudFront might remove the object before its expiration date. For more information on when CloudFront evicts objects, see Managing how long content stays in the cache (expiration).
If you're seeing the "X-Cache:Miss from CloudFront" response intermittently, then CloudFront might be removing the object because of infrequent requests.
Is the CloudFront distribution configured to forward any headers, cookies, or query string parameters?
If your distribution is configured to forward headers, cookies, or query string parameters, then the distribution caches requests based on those parameters. The parameters reduce the number of requests served from the cache.
For example, if two requests to access an object have different values in query string parameters, then the second request isn't served from the cache. The second request returns the "X-Cache:Miss from CloudFront" response.
To determine if forwarding headers, cookies, or query string parameters are causing the response, configure the CloudFront distribution to not forward these parameters to the origin. Then, check to see if the issue persists.
If the issue resolves after the distribution no longer forwards those parameters, then at least one parameter is causing the response. Rather than configuring CloudFront to forward a wide range of parameter, add to the allow list only the specific parameters you want CloudFront to forward.
Is the response stored in the browser cache?
After a request returns the "X-Cache:Miss from CloudFront" response, the browser might serve the same response to subsequent requests because it's stored in the browser cache.
To verify if the response is stored in the browser cache, clear the browser cache and make a new request for the same object.
Note: To determine how long the browser caches the object, check to see if any Cache-Control or Expires headers are set on the object.