I store user-uploaded images in the Google App Engine datastore as db.Blob
, as proposed in the docs. I then serve those images on /images/
There might be a simpler solution here. This requires that you never overwrite the data associated with any identifier, e.g. modifying the image would create a new id (and hence a new URL).
Simply set the Expires
header from your request handler to the far future, e.g. now + a year. This would result in clients caching the image and not asking for an update until that time comes.
This approach has some tradeoffs, like ensuring new URLs are embedded when images are modified, so you have to decide for yourself. What jbochi is proposing is the other alternative that puts more logic into the image request handler.