1

I'm having a hard time making a decision on how to handle user generated uploads without storing filename values in a database. When a user uploads say, a profile avatar/image, I create it on the CDN. My avatar helper in PHP knows the container's url so I can simply echo 'http://cdn-static-url.com/'.$userId.'.jpg

But if a user re-uploads/changes their avatar, the old image is still cached across the CDN until the TTL expires, or I send a purge request (I use Cloud Files and have unlimited purge requests, but even then, the purge is not immediate).

How should I allow for the re-upload of an image, and either;

  • force the change immediately,
  • alert the user of the status of the purge ("Your new image may take X amount of time to update", I've never even seen this)
  • create a new object on the CDN which would mean storing the reference to the filename in MySQL (then I would be doing a SELECT every time I wanted to echo the avatar url on the page...)
  • use the above and leverage Memcache for each object's current url?
Draculater
  • 2,280
  • 1
  • 24
  • 29

1 Answers1

4

A very cheap, but commonly used option in practice, is to generate revision id on each change. Then you would use that revision to refer to an entirely new file name (<revision>.extension) or append the revision to semantically relevant url as a query parameter (user/profile.jpg?<revision>).

Mirko Adari
  • 5,083
  • 1
  • 15
  • 23
  • Got it. But I guess I would need to store the revision/version number in a database table? – Draculater Feb 24 '13 at 21:51
  • 1
    What I've done is to maintain a updated_at column and hash it to generate an id. But the concept remains the same no matter what technical implementation you'd decide upon. – Mirko Adari Feb 24 '13 at 21:52