not reset cache when click Purge rest cache
haidvams opened this issue · 29 comments
I can rest by button "Purge rest cache"
and what option to rest cache auto when I update a post?
thank all
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.
Applying some debugging, on both Strapi and Redis sides, I noticed that the key being deleted is not the actual key that has to be deleted.
Eg.:
- Key being cached
strapi:development:strapi-app1:/api/testimonials?filters={"application":{"name":{"$eq":"app1"}}},sort=["id:asc"]&
- Key trying to be deleted (fails):
/api/testimonials?filters={"application":{"name":{"$eq":"app1"}}},sort=["id:asc"]&
In our configuration we are using a keyPrefix.
The cache is actually working for caching requests (RECV works as expected), but the purge cache is failing.
Just figured out a workaround that worked for us.
For some strange reason I can't figure out the keys()
function on the strapi-plugin-rest-cache/server/services/cacheStore.js
has the following return code:
return keys .filter((key) => keysPrefixRe.test(key)) .map((key) => key.replace(keysPrefixRe, ''));
The keys function is used only on the purge and reset functions.
Commenting the .map
line solves the delete issue.
@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 del
function.
Check my pull request.
@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:
contentTypes: [
"api::novel.novel",
"api::chapter.chapter",
"api::tag.tag",
],
Frontend:
pages/novel/[slug]/[id]
/api/novels/?filters[slug][$eq]=${context.params.slug}&populate=*
/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.
The cache button does not appear in "production" mode for strapi. Except that I would like it to appear.
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 (/).
Due to this slash, the regular expression could not find any matches and was unable to clear the cache.
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."
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".
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)