Update and remove cached image using Liipimaginebundle
Here is a solution that works fine
services: project.cacheimage_listener: class: Project\DashboardBundle\Listener\CacheImageListener arguments: ["@liip_imagine.cache.manager"] tags: - { name: doctrine.event_listener, event: postUpdate } - { name: doctrine.event_listener, event: preRemove }
create the listener
namespace Project\DashboardBundle\Listener;use Doctrine\ORM\Event\LifecycleEventArgs;use Project\DashboardBundle\Entity\Image;class CacheImageListener{protected $cacheManager;public function __construct($cacheManager){ $this->cacheManager = $cacheManager;}public function postUpdate(LifecycleEventArgs $args){ $entity = $args->getEntity(); if ($entity instanceof Image) { // clear cache of thumbnail $this->cacheManager->remove($entity->getUploadDir()); }}// when delete entity so remove all thumbnails related public function preRemove(LifecycleEventArgs $args){ $entity = $args->getEntity(); if ($entity instanceof Image) { $this->cacheManager->remove($entity->getWebPath()); }}}