This post will show you how to set up caching for GraphQL and Rest on Strapi 5, using the Strapi-Cache plugin and Redis. First, here's a bit of context and why I needed it:
The Need for Caching
Even if your site is cached by Cloudflare or something different, you still may need caching for the Strapi API. One example I have is during site builds.
Prototypr frontend is a Next.js app, and the backend is Strapi CMS. The site is deployed statically so all the HTML is generated on the server so the load time is instant for end users.
However, because there's 1000s of pages on the site, it takes about 30 minutes to build all those pages and deploy. This deployment process overloads Strapi with requests as it doesn't hit Cloudflare - it's directly making thousands of API calls, making Strapi really slow for end users during deployment time!
Because I deploy often, I need a way to do it without slowing down the site for everyone, so I came across caching as a solution, and in particular, this Strapi plugin called Strapi-cache by TupiC:
Introducing Strapi-Cache Plugin
Strapi-cache handles both Rest API and GraphQL caching, which is great. It also comes with purging all ready to go, so you don't need to modify lifecycles to clear your cache. It already hooks into relevant hooks such as updating a post:
The features listed are:
Cache Invalidation: Automatically invalidate cache on content updates, deletions, or creations.
Purge Cache Button: UI option in the Strapi admin panel to manually purge the cache for content-types.
Route/Content-Type Specific Caching: Users can define which routes should be cached based.
Switchable Cache Providers: Support for caching providers like Redis







Buy me a coffee


