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
Adds dynamic query cache-control #4540
Conversation
Awesome Tobias, will go through it tonight |
Kudos, SonarCloud Quality Gate passed! |
bc441e9
to
973214d
Compare
d16ae6f
to
ba65ac9
Compare
Kudos, SonarCloud Quality Gate passed! |
@tobias-tengler Thanks. with this branch, can we try cacheControl directive. It would be great, if any usage snippets added here. |
@tobias-tengler @michaelstaib Thank you. It would be great if this can be targeted to v13 |
@zf-jsk You can try out the HTTP query cache by registering it like this: services.AddGraphQLServer()
.AddHttpQueryCache()
.UseQueryCachePipeline()
// optional:
.ModifyCacheControlOptions(options => { }) You can then use the I haven't worked on this in a while, so I'm no longer sure what the current limitations are, but if I remember correctly it should cover basic use cases. If custom caches are not part of the first iteration then I think this could go into v13. I'll try to spend some time on it to get it usable with HTTP Cache-Control. :) |
Allow to annotate the GraphQL schema with caching hints and add middleware that dynamically computes the cache expiration time on a per query basis. In this first iteration these cache hints are used to set the HTTP
Cache-Control
header, but I've also did some preparation work for custom user-space cache implementation for example using Redis. However there were some open questions around short-circuiting and cache key computation that were stalling the original PR, so I decided to leave them out.Closes #2089
Examples
The examples below only show how to apply the
@cacheControl
directive on object type fields, but the directive can also be applied on object types, interfaces and union types. If a field returns a type that specifies a@cacheControl
directive, the field will use the cache information from the type, unless the field itself specifies a@cacheControl
directive.Annotation-based
Code-first
Schema-first