strapi-middleware-cache icon indicating copy to clipboard operation
strapi-middleware-cache copied to clipboard

Caching doesn't seem to be working

Open mehdilouraoui opened this issue 3 years ago • 11 comments

Hey!

Firstly, many thanks for this very useful package! 👍

I've added the following code in at config/middleware.js

module.exports = ({ env }) => ({
    settings: {
      cache: {
        enabled: true,
        models: ['grid'], 
      }
    }
  })

I can see the mounting and the using storage engine logs but I have no log from the caching routes. I also tried with grids, nothing happens.

Here are the logs:

$ strapi develop
[2020-11-23T20:27:40.633Z] debug [Cache] Mounting LRU cache middleware
[2020-11-23T20:27:40.634Z] debug [Cache] Storage engine: mem

Missing this log : debug [Cache] Caching route /grids/* [maxAge=3600000]

Any idea?

Many thanks :)

mehdilouraoui avatar Nov 23 '20 20:11 mehdilouraoui

Hi @mehdilouraoui

That does seem off, although I don't have enough here to debug. Is the repo public by any chance ?

patrixr avatar Nov 26 '20 07:11 patrixr

Same issue here, it's not caching anything, i also don't have the debug [Cache] Caching route /grids/* [maxAge=3600000] log .

Jbmanllr avatar Jan 12 '21 18:01 Jbmanllr

Hi @Jbmanllr

Could you please share the following:

  • your middleware config file
  • strapi version
  • cache middleware version

patrixr avatar Jan 13 '21 04:01 patrixr

Sure! Thanks for your help:

  • Middleware: module.exports = { gzip: { enabled: true, options: { br: false } }, cache: { enabled: true, models: ['pros'], } };

Strapi version: 3.4.1

Middleware version: "strapi-middleware-cache": "^1.2.0",

Jbmanllr avatar Jan 13 '21 09:01 Jbmanllr

I've encountered the same issue, after debugging for a while I found out the reason:

https://github.com/patrixr/strapi-middleware-cache/blob/b32979ab03d52699b47888e996aaf54918d6fcde/lib/index.js#L202

SHOULD BUST? [ '/learn_articles/test-article?' ]
[
  /^\/learn_articles\/1/,
  /^\/learn_articles\?/,
  /^\/authors/,
  /^\/learn_tags/
] => []

So the issue in my case is that the library assumes I'm using IDs, but I'm actually using slugs instead of IDs which kind of breaks the system.

Xerios avatar Feb 12 '21 04:02 Xerios

Gonna go with another cache, this one is not maintained.

Jbmanllr avatar Feb 15 '21 14:02 Jbmanllr

I've encountered the same issue, after debugging for a while I found out the reason:

https://github.com/patrixr/strapi-middleware-cache/blob/b32979ab03d52699b47888e996aaf54918d6fcde/lib/index.js#L202

SHOULD BUST? [ '/learn_articles/test-article?' ]
[
  /^\/learn_articles\/1/,
  /^\/learn_articles\?/,
  /^\/authors/,
  /^\/learn_tags/
] => []

So the issue in my case is that the library assumes I'm using IDs, but I'm actually using slugs instead of IDs which kind of breaks the system.

To use Slugs this would be a custom route that the middleware layer isn't aware of, for something like this you would need to customize the middleware.

derrickmehaffy avatar Feb 16 '21 14:02 derrickmehaffy

I'm aware, just pointing out to whoever might encounter any issues when using custom routes.

I was expecting this library to be less complicated. In my usecase I rarely update the content, so simply caching everything and busting everything when I do any sort of change would've been more than enough 😄

Xerios avatar Feb 16 '21 15:02 Xerios

Hello @mehdilouraoui your issue should have been resolved as of 1.5.0 release !

For custom routes (with slugs), can you add a sample of what you need in comment on the #43 PR ?

stafyniaksacha avatar Feb 25 '21 19:02 stafyniaksacha

@mehdilouraoui @Xerios @Jbmanllr you can test the beta branch with strapi-middleware-cache@beta package tag !

stafyniaksacha avatar Feb 26 '21 09:02 stafyniaksacha

Any news about this? have same issue

davidmgrana avatar Oct 17 '21 01:10 davidmgrana