Skip to content

Add option to disable GET request cache#3

Merged
trevor-scheer merged 9 commits into
apollographql:mainfrom
smyrick:request-cache
Aug 19, 2022
Merged

Add option to disable GET request cache#3
trevor-scheer merged 9 commits into
apollographql:mainfrom
smyrick:request-cache

Conversation

@smyrick

@smyrick smyrick commented Aug 19, 2022

Copy link
Copy Markdown
Member

Back-port from Apollo Server 3 repo: apollographql/apollo-server#6650

Fixes apollographql/apollo-server#6603

By default, RESTDataSource caches all outgoing GET requests in a separate memoized cache from the regular response cache. It makes the assumption that all responses from HTTP GET calls are cacheable by their URL.
If a request is made with the same cache key (URL by default) but with an HTTP method other than GET, the cached request is then cleared.

This change adds a new class property requestCacheEnabled (which defaults to true to match current behavior) which allows users to disable the cache. You might want to do this if your API is not actually cacheable or your data changes over time.

Separately it documents this feature exists and adds more info about how to set a TTL for the entire HTTP cache

@smyrick smyrick marked this pull request as ready for review August 19, 2022 21:53
@trevor-scheer

Copy link
Copy Markdown
Contributor

Tests and prettier passing locally, going to merge and double check when it lands. Classic "Circle sometimes doesn't run on forks" 🥳

@trevor-scheer trevor-scheer merged commit d2e600c into apollographql:main Aug 19, 2022
@smyrick smyrick deleted the request-cache branch August 19, 2022 22:12
@github-actions github-actions Bot mentioned this pull request Aug 19, 2022
trevor-scheer pushed a commit that referenced this pull request Aug 22, 2022
Rename property for RESTDataSource from requestCacheEnabled to memoizeGetRequests

From the initial PR, the name of the new property was a little confusing since there are actually 
two caches, but what is being cached is the response data in the end.

Original PR #3
Back-port of apollographql/apollo-server#6834
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Undocumented and non-configurable memoization feature on apollo-datasource-rest

2 participants