Currently working on a Symfony 3 application. I created a service that lets users upload an image, then choose a crop section, and finally saves the avatar with a specific height and width. Avatars are saved in the /web/img/uploads/avatar/
folder. I'm using the user id to name the file. So the user with the id 13 will have his avatar saved at /web/img/uploads/avatar/13.png
.
My problem is that, when an user updates his avatar, the file is correctly replaced in the folder, but on the actual website the avatar displayed remains the old one for a while.
In dev environment this takes something like a few minutes before the new avatar replaces the old one. Even if I go to the avatar url (localhost/app_dev.php/img/uploads/avatar/xxx.png
) I still see the old avatar for a while before it's eventually replaced by the new one. Tho, the avatar in the filesystem is instantly replaced, as expected.
I figured this might come from the cache. I tried searching for solutions on google but all I found was related to the LiipImagineBundle and its cache manager, but I'm not using this bundle...
I tried deleting the old avatar if it exists after figuring out its name, and before actually croping and saving the image. As follows.
if(file_exists($dst)) {
unlink($dst);
}
But it doesn't work. At all.
Any ideas?