What I do in my app is when a user uploads profile pic, I write the imagedata in document folder, in other words I store the image. When a user removes profile picture, that file is deleted. So that is basic.
But I also remove this file when user logs out, because if I don't then if he logs out and logs in with different username, same profile pic appears. So What I do is, I at the time of login, download user's profile pic(pic URL is given in login API as I send this pic while uploading) in a global thread. But this is not the best solution as everytime user logs in, it takes time to download the image.
What is the best solution for this?