Skip to content

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

@cliftonc

Description

@cliftonc

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions