Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

API Gateway cache not working

How to enable proper caching for an API Gateway endpoint?

I've enabled the API cache (see screenshot), but when I request the URL, the response time stayed the same as before.

I tried enabling the API cache option:

Cache option

And configured the Cache-Control header:

Cache-Control header

And also enabled caching by a query parameter:

Query param cache

like image 906
katspaugh Avatar asked Nov 11 '15 15:11

katspaugh


2 Answers

Caching in API Gateway is not implemented via CloudFront. API Gateway creates a CloudFront distribution on your behalf when you create your API, but caching is actually implemented via use of dedicated caching infrastructure. Even with caching enabled you will continue to see "cache miss" headers from CloudFront.

like image 109
Bob Kinney Avatar answered Oct 27 '22 07:10

Bob Kinney


I found the AWS forum provided some more insight, incase it helps anyone else.

API Gateway integrates with CloudFront behind the scenes. We automatically create a global CloudFront distribution for your APIs in order to reduce the latency perceived by end users. However, the API Gateway cache is handled in the region where API Gateway runs and your API is deployed. Requests are accepted by the CloudFront PoP and then sent to the API Gateway in its origin region, that's where API Gateway will check against its cache and return a cached response if possible. At the moment API Gateway does not use CloudFront's cache at the edge.

like image 31
singh1469 Avatar answered Oct 27 '22 07:10

singh1469