I'm using Rails + Paperclip + S3. I'm looking to host my assets to Cloudfront using one of my S3 buckets.
I know that Cloudfront caches assets but that you can break that cache by configuring it to forward query strings from the origin.
When I modify an asset I expect this to happen
updated_at
timestamp of the ActiveRecord object is updated.updated_at
time.However, it looks like Paperclip isn't properly updating the updated_at
timestamp. Maybe it's cached somehow. Therefore the query string doesn't update and Cloudfront never breaks the cache.
My model is:
class UserImage < ActiveRecord::Base
has_attached_file :image
end
>> ui = UserImage.find(576925)
>> ui.image.class
=> Paperclip::Attachment
>> ui.touch
>> ui.updated_at.to_i
=> 1386241041
>> ui.image.updated_at
=> 1386240937
Those two updated_at timestamps should be the same.
It looks like this might have been a bug with earlier versions of Paperclip (I'm on 2.7) as it works on future versions.
For reference this is how I got it working. In the after_update on my model I force refreshed the instance as follows:
image.instance_write(:updated_at, Time.now.utc)
self.send(:update_without_callbacks)
I had to do update_without_callbacks
so that it wouldn't get stuck in an infinite loop in the callback.
Now the updated_at
time on the Attachment is updated, forcing refresh on Cloudfront.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With