apollo-server icon indicating copy to clipboard operation
apollo-server copied to clipboard

apollo-datasource-rest caching everything

Open westphalen opened this issue 4 years ago • 3 comments

apollo-datasource-rest has a HTTPCache that probably works fine, but it is never invoked because RESTDataSource caches the promise itself, the first time it is called (for GET requests).

This seems to defeat the purpose of having HTTPCache altogether, but looking at the Git history, a good deal of work was put into this memoization, so maybe there is a reason for it?

https://github.com/apollographql/apollo-server/blob/f25784d51130bbb9014b727e2f231e5a737f4a50/packages/apollo-datasource-rest/src/RESTDataSource.ts#L270

westphalen avatar May 05 '20 21:05 westphalen

I guess this is why 408 timeout errors for GET requests are cached 🤔

frandiox avatar Jul 07 '20 05:07 frandiox

I ran into this issue as well, and the cause turned out to be me not instantiating a new datasource for every request. More detail can be found in this comment, thought I share it here.

While HTTPCache is responsible for long-term caching based on HTTP semantics and TTL, memoization makes sure we don't perform the same REST call twice within the same GraphQL request.

hojason117 avatar Jan 13 '21 01:01 hojason117

Hi there, I just posted a detailed description of the problem. Hope you find it useful until/if the issue gets fixed

Jaxolotl avatar Jun 22 '22 21:06 Jaxolotl