1

I am developing an architecture that needs to be rather scalable, I was am wondering how to handle my user images.

Currently, I have been storing a user's image as a file like so:

/users/{user id}/normal.jpg
/users/{user id}/small.jpg

The problem is that I tend to run into caching issue's with the persons' browser e.g. when the user uploads a new image, it overwrites the normal.jpg and small.jpg, but the the user's browse doesn't immediately reflect the change.

Would it be better to not delete any images?

johnnietheblack
  • 13,050
  • 28
  • 95
  • 133

2 Answers2

2

One way you could handle this is to use the timestamp of the last change of the image file as paramether in the html code. Something like

<img src="normal.jpg?t=<timestamp>">

You can calculate it using the function stat().

NullUserException
  • 83,810
  • 28
  • 209
  • 234
1

Give newly uploaded images any kind of random name, that should get rid of caching problems. For example:

/users/{user id}/normal_{timestamp_of_upload}.jpg

Whenever a new upload is done, remove the old one and put the new one in place. Off course you'll need to track the actual filename somewhere in your database along with the user's other info.

Oldskool
  • 34,211
  • 7
  • 53
  • 66