Reputation: 4941
I have a GET endpoint that looks like this:
GET /tenant/:tenantId/groups?user=userName
Now, there is a corresponding POST endpoint as well. When the POST endpoint is used to update groups for the given username, I would like to defeat the cache for this GET endpoint with the username.
POST
request could be made by any user and not necessarily just this user so that the front-end would not know to call the API with the
Cache-Control: max-age=0
How do we invalidate the cache of an API gateway based on path parameters and query parameters?
Upvotes: 0
Views: 2772
Reputation: 729
Are you using DynamoDB to store your data?
If so, you could you use a DynamoDB Stream to trigger a Lambda function that clears the API Gateway cache for that specific record's cache key parameters.
See this AWS resource if you need to set up an IAM policy or create a signed request. https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-caching.html
Upvotes: 1
Reputation: 1811
api gw caching is very straight forward
Cache invalidation on the other hand is normally passed in as a header to that endpoint. If you can live with an eventually consistent model then the default of 300 seconds is normally fine.
Assuming that's not good enough and you require the POST to invalidate the other api's you could:
aws apigateway flush-stage-cache help
Upvotes: 1