- Neueste
- Die meisten Stimmen
- Die meisten Kommentare
Hello.
As CloudFront works, if there is no cache at the edge location, it accesses the origin server and retrieves the content.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/HowCloudFrontWorks.html
Also, the TTL set in the CachingOptimized policy is quite long, so once the image is cached, the image will basically be displayed from the cache.
Therefore, one possible reason why images sometimes fail to load from cache is accessing edge locations that are not cached.
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/using-managed-cache-policies.html#managed-cache-caching-optimized
By checking "x-amz-cf-pop" included in the response header when the data is read from the cache and when it is not read, you may be able to find out the difference in the edge location being accessed.
https://repost.aws/knowledge-center/cloudfront-x-cachemiss-error
When you're experiencing issues with images not loading from the cache in CloudFront despite using the Managed-CachingOptimized policy, there could be several reasons for this behavior. Let's explore some potential causes and solutions:
-
Cache key composition: The Managed-CachingOptimized policy is designed to maximize cache hits, but it may not include all the necessary elements in the cache key for your specific use case. For instance, if your origin server uses certain HTTP headers or query strings to determine which image to serve, these might not be included in the default cache key.
-
TTL settings: Check the Time to Live (TTL) settings in your cache policy. If the TTL is set too low, objects might be evicted from the cache before they can be served to subsequent viewers.
-
Origin headers: Ensure that your origin server is sending appropriate caching headers (Cache-Control, Expires) with the images. If these headers are missing or set to very short durations, CloudFront might request the image from the origin more frequently than necessary.
-
Viewer request variations: If your viewers are sending requests with varying headers, cookies, or query strings that are included in the cache key, it could lead to multiple cached versions of the same image or reduce cache hit rates.
-
Compression settings: If your origin is serving compressed images and the cache policy is not configured to handle compressed objects correctly, it might cause cache misses.
-
Cache behavior settings: Verify that the cache behavior for your images is correctly configured and that the Managed-CachingOptimized policy is indeed applied to the correct path pattern.
To address these issues:
- Review your cache policy settings and consider creating a custom policy if the managed policy doesn't meet your specific needs.
- Adjust TTL settings if necessary to keep objects in the cache longer.
- Ensure your origin server is setting appropriate caching headers.
- Analyze viewer requests to identify any unnecessary variations that might be affecting the cache key.
- Check compression settings in your cache policy and ensure they align with your origin's behavior.
- Verify cache behavior configurations in your CloudFront distribution.
If the issue persists after checking these points, you may need to use CloudFront's logging features or real-time logs to gain more insight into the caching behavior and identify the root cause of the problem.
Sources
Understand the cache key - Amazon CloudFront
Understand cache policies - Amazon CloudFront
Control the cache key with a policy - Amazon CloudFront
CachePolicyConfig - Amazon CloudFront
Relevanter Inhalt
- AWS OFFICIALAktualisiert vor einem Jahr

Hi, I'm facing similar problem.
The images are disappering time to time for some users, when clearing the cache in cloudfront works and some time if the user change their network in that case also works.
my question is: if the image cache is expired then that request should go to origin (s3) then fetch the image and show it to user right?
why the image disappers. please help me to understand this.