I'm using amazon Cloudfront CDN with S3 behind as the origin server to serve images like profile photos of users on my application. I store a user's profile photo with file name as <userId>.jpg
. When the user changes his profile photo, how do I refresh the image in the CDN immediately ?
Since the filename is <userId>.jpg
I cannot have a new name for the new image.
You'd want to store a count of how many times it has been changed and use something like <userId>.jpg?v=2
on your site. You'd have to turn query strings on for the CloudFront distribution.
Without a filename change or query string change, you'd have to use a CloudFront invalidation, which will take up to about 15 minutes to take effect everywhere.