nestjs-gql-cache-control
nestjs-gql-cache-control copied to clipboard
Possibility to bypass cache with argument?
Nice package.
Would be nice with a way to bypass the cache using input arguments from the client
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