jahanzaib younis
jahanzaib younis

Reputation: 17

AWS API Gateway cache "giving x-cache: Miss from cloudfront" while cache cluster and ttl is enabled on required get method

I have setup an api gateway for a suggestions api hosted on aws ecs fargate behind an application load balancer. i have enabled cache for api gateway stage and respective get method with TTL set to 1hr. when i access the api endpoints multiple times and inspect response header, i get

cache-control: no-cache, private x-cache: Miss from cloudfront

since api gateway uses cloudfront under the hood for caching I am confused why there is cache miss all the time.

since this api gateway is using proxy integration, i can not configure integration response. so i tried sending cache-control header value in method response but still the same issue. so i am kinda stuck here. api is working and all but business is critical regarding response time so need to fix this. any help in understanding cache miss would be great. does api gateway use cloudfront cache or just cloudfront edge location to route requests?

Upvotes: 0

Views: 28

Answers (1)

Asfar Irshad
Asfar Irshad

Reputation: 743

Inspect Backend Headers:

Verify what Cache-Control response headers your backend service is returning. If they include no-cache or similar, CloudFront will not cache the responses.

API Gateway Method Response Headers:

Even in proxy integration, you can map custom headers in the Method Response. Ensure you explicitly set cache-friendly headers like:

Cache-Control: public, max-age=3600

Check Cache Key Settings:

Ensure that API Gateway's Caching Keys are configured correctly to include the parameters you want to cache (e.g., query strings, headers).

Also while calling this API, make sure you are not sending cache-control: no-cache or similar request headers

Upvotes: 0

Related Questions