Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rest-cache is not aware of transformer plugin (or vice versa) #25

Closed
orvad opened this issue Jun 27, 2022 · 9 comments
Closed

rest-cache is not aware of transformer plugin (or vice versa) #25

orvad opened this issue Jun 27, 2022 · 9 comments

Comments

@orvad
Copy link

orvad commented Jun 27, 2022

Thanks for an awesome plugin :-)

When using strapi-plugin-transformer and rest-cache plugin only the first request from api is transformed. Subsequent and therefore cached api requests are not transformed.

Strapi 4.2.0
strapi-plugin-transformer 2.0.2 (Latest NPM)
strapi-plugin-rest-cache 4.2.4
strapi-plugin-rest-cache-provider-memory 4.2.4
Node 14 + 16

I have tried different orders in the plugins.js and different settings for each plugin, but it makes no difference. I have also tried disabling all other plugins (sentry, aws-upload, email).

It seems that somehow the rest-cache plugin is not aware of the transformer plugins transformations before storing it in cache.

Here are my rest-cache settings:

  "rest-cache": {
    config: {
      provider: {
        name: "memory",
        getTimeout: 500,
        options: {
          max: 32767,
          updateAgeOnGet: false,
          // maxAge: env("MAX_AGE", 60000),
        },
      },
      strategy: {
        contentTypes: [
          // list of Content-Types UID to cache
          "api::competition.competition",
          "api::photo.photo",
          "api::photographer.photographer",
        ],
      },
    },
  },

And the strapi-plugin-transformer settings:

  transformer: {
    enabled: true,
    config: {
      prefix: "/api/",
      responseTransforms: {
        removeAttributesKey: true,
        removeDataKey: true,
      },
    },
  },
@stafyniaksacha
Copy link
Member

Hello !
What is the load orders of your plugins ? (they are loaded sequentially, depending on how they are defined in config/plugins.js)

@orvad
Copy link
Author

orvad commented Jun 27, 2022

Hi

Thanks for getting back to me.

I have tried both rest-cache first and last. Makes no difference :-/

Different load orders I have tried:

transformer
sentry
upload
email
rest-cache

rest-cache
transformer
sentry
upload
email

transformer
rest-cache
# sentry
# upload
# email

rest-cache
transformer
# sentry
# upload
# email

@jsanta
Copy link

jsanta commented Jul 1, 2022

Happens the same for me. Also tried changing the order of the plugins with no result. The request ends up transformed, but the rest cache keeps the original non transformed value, checked this using Redis.
I would expect that unless explicitly stated, rest cache should cache the final response value, even after custom middlewares.

@jsanta
Copy link

jsanta commented Jul 1, 2022

Just thinking outloud, to my understanding, when a request is received it should first look if there's a cache entry, if yes respond with it, therefore saving unnecessary function executions and else. Otherwise execute all middleware functions and at the end (unless you say so and prefer to store the original data) make a new cache record.
Still don't fully understand Koa's middleware execution order, but I suspect (might be wrong) that this is due to the 'use' middlewares vs the route function middlewares.

@ntarandek
Copy link

ntarandek commented Jul 22, 2022

Anyone had any luck with this one?

EDIT: There is light at the end of the tunnel.

strapi-community/strapi-plugin-transformer#29 (comment)

@BabyDino
Copy link

Was just about to reply, saw your edit and good catch! Was looking into this issue as well. So basically it is the transformer which has issues because it cannot detect a cached call? Is that right?

@ntarandek
Copy link

ntarandek commented Jul 22, 2022

Exactly - cached results return completely different context data. Checking the possible results now ...

@BabyDino
Copy link

Thinking out loud: would it be possible to change the response of the cache so the transformer understands?

@stafyniaksacha
Copy link
Member

Should be resolved by #35 and available on 4.2.5
Do not hesitate to reopen the issue if needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants