Cache purging issue when ApiResources are mapped to Doctrine entities using the default object mapper #7484
Unanswered
alecszaharia
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone!
I have an interesting situation and I’ll try to keep it short.
Following the best practices from the documentation, I ended up with the following ApiResource and Entity setup:
The entity:
Now because the ApiPlatform does not come with a TagCollectorInterface implementation (which is fine, as tagging strategies can differ) I implemented my own tag collector returning the IRI of the resource:
Enabled cache invalidation in api platform config:
Up to this point, everything works fine — the tags are correctly added to the responses.
However, I’ve run into a few issues:
When I send a POST/PUT/PATCH request, the purger is not called!
After some debugging, I found out that the ResourceClassResolver does not resolve the resource class mapped to Doctrine entities.
In short, from what I understood from the code, it iterates through all resource classes and checks if the provided entity is an instance or subclass of a resource class, which does not cover all cases (custom mappers / default mapper ...).
Looking at the PurgeHttpCacheListener, when the ResourceClassResolver returns “negative”, it tries to resolve the resource class by looking at the #[Map] attribute on the entity class. But as you noticed, I have the Map attribute only on the SymbolResource class, so this check also fails, and in the end, there are no resources to be purged.
To me, trying to resolve the resource class in PurgeHttpCacheListener seems to violate the SRP a bit, and this logic should be in the ResourceClassResolver.
Another problem with PurgeHttpCacheListener: it converts all collected resources to IRIs and sends the IRIs to the purger. But what if I have a different tagging strategy?
Am I doing something wrong here, or have I misunderstood something in how API Platform handles resource mapping and cache invalidation?
Beta Was this translation helpful? Give feedback.
All reactions