Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Single type has many relation data update doesn't bust the cache #65

Open
lukawski opened this issue Oct 22, 2021 · 5 comments
Open

Single type has many relation data update doesn't bust the cache #65

lukawski opened this issue Oct 22, 2021 · 5 comments

Comments

@lukawski
Copy link

Hello, thanks for this great package! I noticed that if I have a single type model with hasMany relation, updating data in the related model doesn't bust this single model cache.

That's how my relation looks like.
image

I wonder, is there any way to make it work? Or it would require changes in the middleware code itself?

@patrixr
Copy link
Owner

patrixr commented Oct 23, 2021

Hi @lukawski

Have you tried setting the clearRelatedCache option in the configuration ?

From the readme

By setting the clearRelatedCache to true, the middleware will inspect the Strapi models before a cache clearing operation to locate models that have relations with the queried model so that their cache is also cleared (this clears the whole cache for the related models). The ispection is performed by looking for direct relations between models and also by doing a deep dive in components, looking for relations to the queried model there too.

@lukawski
Copy link
Author

lukawski commented Oct 23, 2021

Hi @patrixr. Yes, I do have clearRelatedCache set to true. I should probably include in in my original question, here is my config

cache: {
      type: 'redis',
      enabled: true,
      clearRelatedCache: true,
      populateStrapiMiddleware: true,
      models: [
        {
          model: 'global',
          singleType: true,
        },
        'category',
      ],
      redisConfig: {
        host: process.env.REDIS_HOST,
        port: process.env.REDIS_PORT,
      },
    },

And here a the versions of Strapi and cache middleware

  • Strapi v3.6.5
  • strapi-middleware-cache v1.5.0

I also took a dive into middleware code and I see that getRelatedModels loops over model attributes to look for related models. I console log in this loop and I can confirm that when I update the entry in categories collection there is no global attribute relation. I guess that's because of how Strapi creates relations on the global model, since its single type it's one-sided I guess. So we only have information about this relation on the Global model but not on the Category.

@stafyniaksacha
Copy link
Collaborator

Hello!
Can you try to update strapi-middleware-cache to latest version (2.1.1) ?

@lukawski
Copy link
Author

Hi @stafyniaksacha, yes, I will, I wanted to wait with it till we have more time on a project but it might be a good idea to do it right now. I will get back to you when I do!

@lukawski
Copy link
Author

@stafyniaksacha so after the update same behavior occurs. When I do update an entry in categories collection cache for the global model is not cleared.

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

No branches or pull requests

3 participants