T
TanStack3y ago
evident-indigo

Invalidate API Gateway Cache when running manual invalidations

Hi there, I have AWS API Gateway with (API Gateway) caching for a GET endpoint that I consume with react-query. I also use mutations when I want to perform a PUT request, and then I invalidate react-query cache for the proper key. But I also need to tell API Gateway that I need fresh data, not data from API Gateway cache, and the way to do that is by using the header Cache-Control: max-age=0, is there an easy way to run the query function with those headers, but only for the manual invalidations?
5 Replies
variable-lime
variable-lime3y ago
Can you not do that as part of the mutation?
evident-indigo
evident-indigoOP3y ago
I have to do the mutation, I have a CRUD, I just need to find a way to check the origin of the query, if it's coming from an invalidation, I want to do the query with different headers to invalidate API Gateway cache.
variable-lime
variable-lime3y ago
what I meant is: if the mutation updates some data, is there no way that the server who handles the update tells the api gateway that the cache needs to be invalidated now? imo, this is not a client responsibility: why should the GET request care if the backend delivers data from a cache or not ...
evident-indigo
evident-indigoOP3y ago
oh got it, the problem is that the way to invalidate API Gateway cache is from the client 🤷‍♂️ https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-caching.html#invalidate-method-caching
Enabling API caching to enhance responsiveness - Amazon API Gateway
Learn how to enable Amazon API Gateway caching to enhance your API's performance.
evident-indigo
evident-indigoOP3y ago
I was trying to find a way/idea to conditionally add the header from the client using react-query, but I agree, it would be more convenient if there was a way to do it in the server.

Did you find this page helpful?