apollographql / apollographql/datasource-rest

Rest Data Source - always checks cache no matter cache settings can we make it configurable?

Open
#425 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
48
Forks
21
PR merge metrics
No merged PRs in 30d

Description

We are actively using Apollo, and the Rest Data Source with Redis as our overall cache for some legacy APIs. We have quite a few GET Api's that we _never_ want cached, that return correct no-cache headers, and to be explicit we have also set the `cacheOptions` ttl to zero.

However, we can still see a lot of un-necessary `MGET url` in our logs, due to the code:

https://github.com/apollographql/datasource-rest/blob/main/src/HTTPCache.ts#L78

This code means that it will always check the cache for every request that is not a `HEAD`.

Would you consider a PR that if the ttl has been manually set to zero, it should not check the cache for values, or perhaps an additional explicit value so as not to break existing behaviour? Something along the lines of:

```
const neverCache = !requestOpts.cache?.cacheOptions?.ttl || !requestOpts.cache?.cacheOptions?.neverCache;
if (neverCache) {
return { response: await this.httpFetch(urlString, requestOpts) };
}
```

This would avoud (for us at least) hundreds of thousands of pointless MGET requests to our cache!

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in src/HTTPCache.ts around line 78 and trace how request cacheOptions, including ttl and no-cache behavior, reach the cache lookup. Verify the intended opt-out behavior against the existing request flow; done means requests configured never to cache no longer issue cache MGET operations while still being fetched successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
redis, typescript
Domain
api, backend, performance
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.