Cache Rest API/Graphql results on to reduce load time?

System Information
  • Strapi Version: 3.5.0
  • Operating System: Ubuntu
  • Database: MongoDB
  • Node Version: 14
  • NPM Version: 7
  • Yarn Version:

Hello, I have a question. In a page I need to call 4 requests, example

How to cache results for those requests to reduce time calling them on frontend for the first time? Are there any server-side cache working? Each request cost me at least 1 second, so the site starting very slow on that page.

I just installed strapi-middleware-cache and it reduce TTFB a lot. Are there any downside to use middleware cache? Still waiting for some advice to optimize the request.

It is ok, I use it too. It is a good option for APIs that do not change their content often.

The only downside currently is if you have policies set on the handlers, the cache will respond before the policies/controllers can be fired (they won’t be at all).

Also the cache middleware doesn’t work on any endpoint that needs security as an authenticated request as it bypasses the users-permissions plugin entirely.

There is no option to cache GraphQL at the moment.

1 Like

So are there any way to cache results of the REST API requests on server-side?

That’s what the middleware cache package does

If you are looking for a graphql cache solution: I found that urqls document cache works really well. In our app, which mostly waits for database responses, this alone brought down the build time from 40 to 12 minutes.

More about how the document cache works: Document Caching | urql Documentation