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

purgeAdmin should also send request.body to cacheStore.clearByUid #55

Open
fliptaboada opened this issue May 29, 2023 · 0 comments
Open

Comments

@fliptaboada
Copy link

Hey team!

I believe the purgeAdmin function should also include ctx.request.body on the params that's sent to cacheStore.clearByUid allowing for url paths that include more than just the id.

Reasoning for that is that today when you hit save on the admin, the params object only include the id of the object, only purging urls that include :id as a result and not working for :slug or other cases, so this example here: https://strapi-community.github.io/strapi-plugin-rest-cache/guide/strategy/cache-custom-routes.html#frontmatter-title does't seem to be purged when hitting save, only when you explicitly click Purge REST Cache on the entity (that already adds the whole object to the cacheStore.clearByUid call).

Here's the change I did that seem to fix the issue:

diff --git a/node_modules/strapi-plugin-rest-cache/server/middlewares/purgeAdmin.js b/node_modules/strapi-plugin-rest-cache/server/middlewares/purgeAdmin.js
index 483a4de..5c24461 100644
--- a/node_modules/strapi-plugin-rest-cache/server/middlewares/purgeAdmin.js
+++ b/node_modules/strapi-plugin-rest-cache/server/middlewares/purgeAdmin.js
@@ -29,7 +29,10 @@ function createPurgeAdmin(options, { strapi }) {
 
     if (!(ctx.status >= 200 && ctx.status <= 300)) return;
 
-    await cacheStore.clearByUid(uid, params);
+    await cacheStore.clearByUid(uid, {
+      ...params,
+      ...ctx.request.body,
+    });
   };
 }
 

This issue body was partially generated by patch-package.

Let me know if that looks good to you guys and I can also send a PR with this.

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

No branches or pull requests

2 participants