Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

whole response caching #326

Open
Tracked by #329
abernix opened this issue Jan 14, 2022 · 3 comments
Open
Tracked by #329

whole response caching #326

abernix opened this issue Jan 14, 2022 · 3 comments

Comments

@abernix
Copy link
Member

abernix commented Jan 14, 2022

Today, the Apollo Gateway supports whole response caching thanks to @mandiwise's contribution of apollographql/federation#870 as an evolution of the @cacheControl story in Apollo Server, which produces cache-control (and age) headers.

The PR above introduced the ability for the Gateway to synthesize a cache policy from cache-control headers of subgraphs and leverage Apollo Server's response cache plugin. In terms of implementation, this leverages uses Apollo Server's responseForOperation plugin hook to short-circuit execution in the event of a cache-hit, and keys things using a cache key that is based on a hash of a variety of things including variables, operationName, etc. — as seen here.

An analysis of the way things are done today should probably be drawn up as a design (or we should ask the Apollo Server team, or do some spelunking to see if a design already exists.)

All of this could be built on a key-value cache abstraction that supports either string in-memory, or in a distributed fashion (à la Memcached/Redis). Though that abstraction could be a separate issue (and also be used to implement other key-value stores that could also be, optionally, distributed, like APQ in #130)

And of course, we should consider any reports we want to sent to Studio, as was once requested in #1009. (See issue)

@glasser
Copy link
Member

glasser commented Sep 23, 2022

Worth noting that one could break out "calculate a cache-control response header based on combining cache-control headers from subgraphs" as a smaller piece from actually implementing caching in the Router, if that's preferable.

@nikomakela
Copy link

Big thumbs up for this one. It would be really beneficial to get some frequently used responses from the Apollo Router's cache when the actual data source is having some outages, or just to make the searches more efficient. If I understood right, that's what this feature would be for? For example, when building a client app with some SEO friendly server side rendered static pages, the data needs to be available and it would be nice to have it quickly for fast CI.

lennyburdette added a commit to lennyburdette/router that referenced this issue Mar 13, 2023
uses cache-control headers from subgraphs to determine an overally cache-control policy

partially addresses apollographql#326
lennyburdette added a commit to lennyburdette/router that referenced this issue Mar 13, 2023
uses cache-control headers from subgraphs to determine an overally cache-control policy

partially addresses apollographql#326
lennyburdette added a commit to lennyburdette/router that referenced this issue Mar 13, 2023
uses cache-control headers from subgraphs to determine an overall cache-control policy

partially addresses apollographql#326
lennyburdette added a commit to lennyburdette/router that referenced this issue Mar 14, 2023
uses cache-control headers from subgraphs to determine an overall cache-control policy

partially addresses apollographql#326
lennyburdette added a commit to lennyburdette/router that referenced this issue Mar 14, 2023
uses cache-control headers from subgraphs to determine an overall cache-control policy

partially addresses apollographql#326
lennyburdette added a commit to lennyburdette/router that referenced this issue Mar 14, 2023
uses cache-control headers from subgraphs to determine an overall cache-control policy

partially addresses apollographql#326
lennyburdette added a commit to lennyburdette/router that referenced this issue Mar 14, 2023
uses cache-control headers from subgraphs to determine an overall cache-control policy

partially addresses apollographql#326
lennyburdette added a commit to lennyburdette/router that referenced this issue Mar 14, 2023
uses cache-control headers from subgraphs to determine an overall cache-control policy

partially addresses apollographql#326
lennyburdette added a commit to lennyburdette/router that referenced this issue Mar 14, 2023
uses cache-control headers from subgraphs to determine an overall cache-control policy

partially addresses apollographql#326
lennyburdette added a commit to lennyburdette/router that referenced this issue Mar 21, 2023
uses cache-control headers from subgraphs to determine an overall cache-control policy

partially addresses apollographql#326
lennyburdette added a commit to lennyburdette/router that referenced this issue Mar 23, 2023
uses cache-control headers from subgraphs to determine an overall cache-control policy

partially addresses apollographql#326
lennyburdette added a commit to lennyburdette/router that referenced this issue Apr 4, 2023
uses cache-control headers from subgraphs to determine an overall cache-control policy

partially addresses apollographql#326
lennyburdette added a commit to lennyburdette/router that referenced this issue Apr 4, 2023
uses cache-control headers from subgraphs to determine an overall cache-control policy

partially addresses apollographql#326
lennyburdette added a commit to lennyburdette/router that referenced this issue Apr 4, 2023
uses cache-control headers from subgraphs to determine an overall cache-control policy

partially addresses apollographql#326
bnjjj pushed a commit that referenced this issue Apr 6, 2023
uses cache-control headers from subgraphs to determine an overally
cache-control policy

partially addresses #326
garypen pushed a commit that referenced this issue Apr 6, 2023
uses cache-control headers from subgraphs to determine an overally
cache-control policy

partially addresses #326
tinnou pushed a commit to Netflix-Skunkworks/router that referenced this issue Oct 16, 2023
@smyrick
Copy link
Member

smyrick commented Apr 2, 2024

For those following along we have released entity caching in Router 1.40.0: https://github.com/apollographql/router/releases/tag/v1.40.0

This is not whole response caching as implemented in the Gateway, it is actually more advanced and can still be used to cache response data

goto-bus-stop pushed a commit to goto-bus-stop/router that referenced this issue Jul 10, 2024
If the schema's output type is a list (`[Type]`) but the response is not a list, this change wraps the response in a list as a convenience to the user.

Without this change, the router's response formatting will silently drop the data.

This is probably the right design choice because the Selection syntax is "agnostic" to arrays, so there's no way for the user to indicate how to handle this situation, nor is there a way to detect this situation during validation (at least not until we have a JSON spec to also validation against.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants