Skip to content

CloudFront Cache Miss for CachingOptimized

0

Hello,

I have a working Pay-as-you-go CloudFront distribution with a Custom Origin outside AWS, to a website that runs at a hosting provider Bluehost: https://pfa.mihaiadam.com .

But I have a configuration issue: for each request, CloudFront logs Cache Miss, there is no Hit. I tried with 2 cache policies: CachingOptimizedand UseOriginCacheControlHeaders. The below logs are with CachingOptimized. Also, Origin request policy is All Viewer. There is only one cache-behavior-path-pattern: the default one.
Considering the log below, and the option CachingOptimized - Policy with caching enabled, shouldn't the cache key be only the URL path of the requested object ? Is the cache done for multiple keys ? Is there a way to log the cache keys ?
Could you please specify why is this Cache Miss ?

{
    "date": "2026-07-16",
    "time": "09:56:33",
    "x-edge-location": "<edge-location-id>",
    "sc-bytes": "24344",
    "c-ip": "<my_ip>",
    "cs-method": "GET",
    "cs(Host)": "<cloudfront-id>.cloudfront.net",
    "cs-uri-stem": "/pricing/",
    "sc-status": "200",
    "cs(Referer)": "https://pfa.mihaiadam.com/contact/",
    "cs(User-Agent)": "Mozilla/5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/150.0.0.0%20Safari/537.36%20Edg/150.0.0.0",
    "cs-uri-query": "-",
    "cs(Cookie)": "-",
    "x-edge-result-type": "Miss",
    "x-edge-request-id": "hu4mdKEI2ZRrudrQ-valgtYCInY-EIwwMXMTB5Ch0Un9ksMEhwwU5A==",
    "x-host-header": "pfa.mihaiadam.com",
    "cs-protocol": "https",
    "cs-bytes": "37",
    "time-taken": "0.713",
    "x-forwarded-for": "-",
    "ssl-protocol": "TLSv1.3",
    "ssl-cipher": "TLS_AES_128_GCM_SHA256",
    "x-edge-response-result-type": "Miss",
    "cs-protocol-version": "HTTP/2.0",
    "fle-status": "-",
    "fle-encrypted-fields": "-",
    "c-port": "60549",
    "time-to-first-byte": "0.557",
    "x-edge-detailed-result-type": "Miss",
    "sc-content-type": "text/html;%20charset=UTF-8",
    "sc-content-len": "-",
    "sc-range-start": "-",
    "sc-range-end": "-",
    "c-country": "RO",
    "cache-behavior-path-pattern": "*"
}

asked a month ago48 views

2 Answers
5
Accepted Answer

Since you are using the CachingOptimized Cache Policy, your cache key is restricted exclusively to the URL path. Your All Viewer Origin Request Policy forwards all data to the origin upon a miss, but in the modern CloudFront policy system, it does not alter the cache key or disable caching on its own.

If you are experiencing a 100% Cache Miss rate on your default behavior, to me, the root cause is almost certainly your Origin (Bluehost/WordPress) returning HTTP response headers that explicitly instruct CloudFront not to cache the object.

Specifically, CloudFront will not cache the response if your origin returns:

  1. Cache-Control directives such as no-cache, no-store, private, or max-age=0
  2. A Set-Cookie header

By default, CloudFront respects the origin's Cache-Control directives. You can easily verify this by running curl -I [https://pfa.mihaiadam.com/pricing/](https://pfa.mihaiadam.com/pricing/) in your terminal and inspecting the response headers.

How to fix it: Either adjust the Cache-Control headers directly at your Bluehost origin, or create a Custom Cache Policy in CloudFront where you set the Minimum TTL to a value greater than 0. Setting a Minimum TTL > 0 forces CloudFront to cache the object and override the origin's restrictive headers.

References:

EXPERT

answered a month ago

EXPERT

reviewed a month ago

  • Thank you for your answer, The Cache-Control was as you expected, and after a Custom Cache Policy in CloudFront, the page cache works !

0

Based on your configuration, there are a few factors that could be causing cache misses with the CachingOptimized policy:

Understanding the Cache Key with CachingOptimized

While CachingOptimized does focus on the URL path as a primary cache key component, it's not the only factor. The cache policy determines which values CloudFront includes in the cache key, which can include HTTP headers, cookies, and URL query strings. CloudFront uses this cache key to find matching objects in its cache.

The Impact of "All Viewer" Origin Request Policy

Your use of the "All Viewer" origin request policy is likely a significant contributor to your cache miss issue. When you configure CloudFront to forward all headers to your origin (which "All Viewer" does), CloudFront doesn't effectively cache the objects associated with this cache behavior. Instead, it sends every request to the origin, resulting in consistent cache misses.

Recommended Solution

To improve caching, you should switch from the "All Viewer" origin request policy to a more restrictive policy that only forwards the headers your origin actually needs. The headers, cookies, and query strings included in the cache key are automatically included in requests to the origin, so you don't need to forward everything.

If you need to send certain values to the origin but don't want them affecting your cache key, you can use a separate origin request policy to specify those additional headers without impacting caching behavior.

Additional Considerations

Keep in mind that caching based on too many headers can affect performance by causing more requests to be forwarded to the origin for the same object. If your origin returns the same content regardless of certain header values, you shouldn't configure CloudFront to cache based on those headers.

Unfortunately, CloudFront doesn't provide a direct way to log the exact cache keys being generated, but understanding which headers, cookies, and query strings are included in your cache policy will help you determine what's being used for cache key generation.
Sources
Cache content based on request headers - Amazon CloudFront
CachePolicy - Amazon CloudFront

answered a month ago

EXPERT

reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.