Skip to content

Possibility to bypass cache with argument? #8

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

Open
simplenotezy opened this issue Apr 11, 2023 · 1 comment
Open

Possibility to bypass cache with argument? #8

simplenotezy opened this issue Apr 11, 2023 · 1 comment

Comments

@simplenotezy
Copy link

Nice package.

Would be nice with a way to bypass the cache using input arguments from the client

@CauanCabral
Copy link

Hi @simplenotezy , I don't know if you found a way to do it, but it's possible using the responseCachePlugin at the module level:

GraphQLModule.forRoot({
  driver: ApolloDriver,
  autoSchemaFile: true,
  sortSchema: true,
  cache: KeyvAdapter(new Keyv(redisConnURI)),
  plugins: [
    ApolloServerPluginCacheControl({ defaultMaxAge: 300 }),
    responseCachePlugin({
      shouldReadFromCache(requestContext) {
        const cacheControl = requestContext.request.http.headers.get('cache-control');
        return !cacheControl || !cacheControl?.includes('no-store');
      },
    }),
})

Reference: https://www.apollographql.com/docs/apollo-server/v3/performance/caching#configuring-reads-and-writes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants