strapi-community / strapi-plugin-rest-cache

Speed-up HTTP requests with LRU cache.
https://strapi-community.github.io/strapi-plugin-rest-cache/
MIT License
129 stars 29 forks source link

does it work with GraphQL? #4

Closed violabg closed 2 years ago

violabg commented 2 years ago

does it work with GraphQL?

stafyniaksacha commented 2 years ago

Hello!

Sorry, this plugin aim only REST api. We will check about GraphQL cache once it's api is finalized.

For now you can use GraphQL middleware: https://docs.strapi.io/developer-docs/latest/plugins/graphql.html#middlewares

// path: ./src/index.js

module.exports = {
  register({ strapi }) {
    const extensionService = strapi.plugin('graphql').service('extension');

    extensionService.use({
      resolversConfig: {
        'Query.categories': {
          middlewares: [
            /**
             * Basic middleware example #2
             * Enable server-side shared caching
             */
            async (next, parent, args, context, info) => {
              info.cacheControl.setCacheHint({ maxAge: 60, scope: "PUBLIC" });
              return next(parent, args, context, info);
            },
          ],
          auth: false,
        },
      }
    })
  }
}