I had an idea to build an onFlush hook. There you have all the entities queued for insertions, updates, and deletions, so you can invalidate caching depending on the name and identifier of an object, etc.
Unfortunately, I have not created event listeners yet, but I definitely plan to build such a thing for my project.
Here is a link to the doctrine documentation for the onFlush event
Edit: There is an even simpler way to implement events. In an entity class, you can add @HasLifecycleCallbacks in the annotations, and then you can define the function using the @PreUpdate or @PrePersist annotation. Each time this model is updated or saved, this function will be called.
class SomeEntity { ... public function preUpdate() {
Maybe this can be used to invalidate every single instance of an object?
source share