-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
not reset cache when click Purge rest cache #23
Comments
Facing the same issue, Rest cache is not being purged when pressing the delete button. In our case we are using the Redis cache store. Eg.:
In our configuration we are using a keyPrefix. |
Just figured out a workaround that worked for us.
The keys function is used only on the purge and reset functions. |
@jsanta thanks for looking into this! Do you think of maybe submitting a PR for for dealing with this issue? |
@jpizzati-uvl truth is I ended up patching the package (as suggested on the Strapi documentation). It was way easier, besides I had to do some other custom modifications. https://gist.github.com/jsanta/75d00e65793f4c6adcc765132fe39369 |
@jsanta not resetting the cache on the list API of a content type.Any solution for that? I am using Redis cache. Earlier i was using memory cache and it was working perfectly but when switched to Redis cache it is not working on list api |
@deepakgupta-unthinkable try the patch I posted in previous comments. I think that should work. If it doesn't you'll have to make further debugging in both Redis and Strapi sides, and also check you plugin configuration. |
@jsanta I tried your patch but not working with in-memory cache |
@jpizzati-uvl sorry about that. Cannot help you further, as even though the patch tries to be generic enough for most use cases, your own mileage may vary and most likely require specific debugging. |
@jsanta you should not patch that way. Instead, fix the |
@dinhkhanh it depends. i also required some other modifications for particular use cases I'm facing. Agreed that a pull request is better for general improvements, but forking and compiling the plugin for very specific business requirements is an overkill. |
Still bugged with in-memory and redis cache using patch. Backend: Frontend: /novel/, [slug], and [id] are caching. purging works, but it's ignoring [id] cache that's deeper inside-in particular the contents that are being filtered. |
Hello, I would like to understand, cache purging does not work naturally with redis? I tried after many attempts the button never works. If I do the purge with an API call directly "/rest-cache/purge" I always have an empty array. Do you have some answers for me? It will help me understand better. Thanks a lot |
In my case, the problem is that in the request I used an additional slash (/). An example of an incorrect request would be "/api/docs/?populate=deep,2" while an example of a correct request would be "/api/docs?populate=deep,2". Once I corrected this, the cache was successfully cleared through the use of the "purge button." |
This may be a PR to match trailing slashes (https://github.com/strapi-community/strapi-plugin-rest-cache/blob/main/packages/strapi-plugin-rest-cache/server/utils/config/getRouteRegExp.js#L16) |
Below of the links suggest that the purge cache issue from Content type was fixed but actually the issue still persist.
Even today I am facing this issue, the cache is not cleared after clicking on Is there any latest update related to this issue from Strapi community? Addendum, is there any other way to apply caching for custom added routes? |
I have a similar issue but only when using "routes -> path". Cache is saving well in Redis and is automatically deleted after chosen time but... cache is not purged when I update an entry OR click PURGE button in CMS. Everything works fine if I do not use "routes" option. Any thoughts? |
I encountered a similar challenge in one of my strapi project and managed it by establishing a connection between the Strapi server and the Redis instance. Leveraging Strapi's lifecycle hooks (afterCreate, afterUpdate, afterDelete, afterDeleteMany), I successfully implemented a cache flush mechanism. This solution effectively manages cache updates in response to CRUD operations, ensuring optimal system performance. |
@girish-soman Thanks for the feedback. I understood the implementation you did in lifecycle but can you show us which redis method did you use flushing caching? |
@Shekhar-Zealous I was using redis.flushall() which gets triggered on the above lifecycle hooks and clears the entire Redis cache. |
@girish-soman How come you used redis.flushall() using this package https://market.strapi.io/plugins/strapi-plugin-rest-cache? Would really appreciate if you share us an example here. |
Hey @Shekhar-Zealous, sharing the code snippet, Step 1: Step 2: Sharing you a sample code.
Step 3: Eg
Sharing the lifecycles documentation here This works well on my use case. Hope this will help you too! Thanks! |
@girish-soman I'd say it's to wide workaround as it will flush WHOLE cache saved in Redis, not the chosen entry or collection. I think that there is a problem with routes path saved in Redis as a key. Saving works fine but then the plugin cannot find the proper key to delete it. No doubt it's a bug as solution WITHOUT routes works well. |
Yes @web-admin , this is the only option I could figure out. Until the plugin itself fixes this, though, it works for my use case. |
@girish-soman I will take a look at the solution you gave. Many thanks. I agree with @web-admin |
@derrickmehaffy Is it possible to look up this issue? Definitely there is an issue with resetting cache when "routes" are enabled. |
Delete Redis data based on the specified key at the points of updating and deleting during the mode lifecycle. // redis.ts
import Redis from "ioredis";
export const redisClient = new Redis({
port: 6379,
host: "127.0.0.1",
});
export async function deleteKeysWithPattern(pattern) {
const keysToDelete = await redisClient.keys(pattern);
if (keysToDelete.length > 0) {
await redisClient.del(keysToDelete);
console.log(`Deleted keys matching pattern '${pattern}':`, keysToDelete);
} else {
console.log(`No keys found matching pattern '${pattern}'`);
}
} // lifecycles.ts
import { deleteKeysWithPattern } from "../../../../utils/redis";
export default {
afterUpdate(event) {
deleteKeysWithPattern(`*api\\\\${event.model.info.singularName}*`);
},
afterUpdateMany(event) {
deleteKeysWithPattern(`*api\\\\${event.model.info.singularName}*`);
},
afterDelete(event) {
deleteKeysWithPattern(`*api\\\\${event.model.info.singularName}*`);
},
afterDeleteMany(event) {
deleteKeysWithPattern(`*api\\\\${event.model.info.singularName}*`);
},
}; // plugins.ts
contentTypes: [
"api::notice.notice",
"api::article.article",
"api::global-config.global-config",
], |
I can rest by button "Purge rest cache"
and what option to rest cache auto when I update a post?
thank all
The text was updated successfully, but these errors were encountered: