Created
July 2, 2009 21:12
-
-
Save jeremy/139719 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Round expiry to encourage HTTP caching. | |
# 5-minute expiry at 6:03 would round up from 6:08 to 6:10. | |
module QuantizedExpiry | |
def url_for(name, options = {}) | |
unless options[:expires] | |
t = (options.delete(:expires_in) || 5.minutes).to_i | |
options[:expires] = t * (2 + (Time.now.to_i / t)) | |
end | |
super | |
end | |
end | |
AWS::S3::S3Object.extend QuantizedExpiry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment