I’m generating expiring signed URI’s with paperclip on S3. However on every request I generate a new URI which is not ideal and it forces the browser to download a new set of images from S3 on every page refresh.
What I’d like to do is cache the generated URI’s for a little less time than they expire on S3. Has anybody done anything like this before and can suggest a solution.
I’m deploying on heroku if that suggests a solution ( or not )
There is an easy way to do this which is quite neat. The paperclip expiring_url method takes an explicit time. So we can do something like
and when we need an expiring URL
The trick is that the image is expired in S3 at the end of the day + 1 hour for any URL generated until the end of the day. New URL’s are generated at 12:00 midnight every night. This prevents images being used off the site for more than 25 hours which should be enough to prevent rampant hot linking but still be enough to allow browsers to cache the images for a day