StarpTech / apollo-datasource-http

Optimized JSON HTTP Data Source for Apollo Server
MIT License
73 stars 32 forks source link

`maxTtlIfError` behavior clarification. #27

Open JustinTRoss opened 2 years ago

JustinTRoss commented 2 years ago

This line makes it appear maxTtlIfError is whatever value is provided in seconds for maxTtlIfError https://github.com/StarpTech/apollo-datasource-http/blob/5f0036f6510790e42c5ecf36900367bb6400514f/README.md?plain=1#L113

This line makes it appear as though maxTtlIfError actually ends up being maxTtl + maxTtlIfError. https://github.com/StarpTech/apollo-datasource-http/blob/5f0036f6510790e42c5ecf36900367bb6400514f/src/http-data-source.ts#L328

I'm happy to PR clarification once I have it. Just need to know what that is 🙃 .

StarpTech commented 2 years ago

Hi @JustinTRoss, you're right this is confusing. The TTL of the error cache must always be longer than the default TTL cache. maxTtlIfError defines the exact duration in seconds of the error cache. We should update docs with this, for example:

maxTtl: 60 // cache requests for 1min
maxTtlIfError: 60 // cache for another 1min when the revalidation requests result in an error.
JustinTRoss commented 2 years ago

Got it. To confirm:

requestCache: {
        maxTtl: 10 * 60, // 10min, will respond for 10min with the result in cache (revalidated every 10min)
        maxTtlIfError: 30 * 60, // 30min, will respond with the result in cache for a further 30 minutes when revalidation attempts result in error (40 minutes total)
},
StarpTech commented 2 years ago

yes, (40 minutes total) is confusing. I'd remove it.

JustinTRoss commented 2 years ago

Agreed. It could be better worded. It sounds like the sentiment is generally true though, that the cached value can be returned for up to 40 minutes. This seems necessary for folks to understand. I'll work on conveying it clearly and send a PR with updated docs.

Thanks again! 🙏

StarpTech commented 2 years ago

Thanks!