nestjs-gql-cache-control icon indicating copy to clipboard operation
nestjs-gql-cache-control copied to clipboard

Possibility to bypass cache with argument?

Open simplenotezy opened this issue 1 year ago • 1 comments

Nice package.

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

simplenotezy avatar Apr 11 '23 21:04 simplenotezy

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

CauanCabral avatar Aug 25 '23 17:08 CauanCabral