alanmynah
alanmynah

Reputation: 221

GCP API Gateway is caching response when Cache-Control header is set

All infra is on GCP. When I set a "Cache-Control: public, max-age=86400" response header on my endpoint that is served by a 2nd generation cloud function, the API gateway is caching the response. When I change my endpoint to set the "Cache-Control: no-cache" response header, the API gateway continues to return the original response, despite the change in cache header. When I call the function's own endpoint I get the correct cache header value.

The flow is: Load Balancer -> API Gateway -> Cloud Functions. Calling via LB gives wrong TTL Calling via API Gateway gives wrong TTL Calling Cloud Function directly gives correct TTL

The API Gateway docs don't mention caching anywhere, Load Balancer does not have caching/CDNs enabled, and given that API gateway is downstream and calling it produces wrong TTL, seems this is the issue originating from API Gateway.

Steps to reproduce:

  1. Create an API gateway with an endpoint with a 2nd generation cloud function as the backend
  2. The endpoint served by the cloud function should set the "Cache-Control: public, max-age=86400"
  3. Deploy the endpoint and verify the response contains the "Cache-Control: public, max-age=86400" header
  4. Deploy a change to the endpoint, changing the response body, and replacing the "Cache-Control: public, max-age=86400" header with "Cache-Control: no-cache".
  5. Observe that the response from the cloud function's direct URL has changed to contain the "Cache-Control: no-cache" header, but the response from the api gateway URL continues to be the old response with the "Cache-Control: public, max-age=86400" header.

The only way I could clear the cache was to deploy a new gateway with the same api spec. Maybe there is a purge functionality that could be invoked, would be keen to explore the options.

Upvotes: 3

Views: 176

Answers (0)

Related Questions