Skip to content

Instantly share code, notes, and snippets.

@jeremy
Created July 2, 2009 21:12
Show Gist options
  • Save jeremy/139719 to your computer and use it in GitHub Desktop.
Save jeremy/139719 to your computer and use it in GitHub Desktop.
# 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