Caching in Strapi with Strapi Middleware Cache

Most firms strive to retrieve and store data faster. It is because no one wants an application that is slow or lags. When there's a lot of data in the database, it becomes challenging to fetch data from the database swiftly, which may cause your application to lag. To avoid this, most software firms cache data.


This is a companion discussion topic for the original entry at https://strapi.io/blog/caching-in-strapi-strapi-middleware-cache

So I’m not sure if this got patched, but according to this github issue, it’s not.

I think it’s pretty important to mention this, especially if you want to cache routes that should not be publicly accessible. So if you want to implement this in production, do take this into account.
@DMehaffy please correct me if I’m wrong about this so I don’t cause any confusion.

Hi! Thanks for the article. It is very helpful. I have 2 questions:

  1. How i can configure the middleware cache if my database model name is ‘posts’ but my routes aren’t /posts/:id and have a different route name, e.g /publications/:id

Because the names of objects in the code are in English but the routes in my case are in Spanish because of my target audience.

  1. This only works for the default routes created by Strapi? Because i create new endpoints with my own business logic and i replace the default routes in some cases. The cache will works in this cases?

thanks,
Alex

Hello Alex, it’s possible to use custom routes. Check this out:

1 Like

Thank you for pointing this out. I’ll include it as a note ASAP so that users are informed.

This is completely correct yes. It’s due to how the middlewares are loaded and this cache runs before the auth.

are there any other approach to auth routes?