instance method
expires_in
Ruby on Rails 2.3.18
Since v2.2.3 Last seen in v2.3.18Available in: v2.2.3 v2.3.18
Signature
expires_in(seconds, options = {})
Sets a HTTP 1.1 Cache-Control header. Defaults to issuing a “private” instruction, so that intermediate caches shouldn’t cache the response.
Examples:
expires_in 20.minutes expires_in 3.hours, :public => true expires in 3.hours, 'max-stale' => 5.hours, :public => true
This method will overwrite an existing Cache-Control header. See www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more possibilities.
Parameters
-
secondsreq -
optionsopt = {}
Source
# File actionpack/lib/action_controller/base.rb, line 1218
def expires_in(seconds, options = {}) #:doc:
cache_control = response.headers["Cache-Control"].split(",").map {|k| k.strip }
cache_control << "max-age=#{seconds}"
cache_control.delete("no-cache")
if options[:public]
cache_control.delete("private")
cache_control << "public"
else
cache_control << "private"
end
# This allows for additional headers to be passed through like 'max-stale' => 5.hours
cache_control += options.symbolize_keys.reject{|k,v| k == :public || k == :private }.map{ |k,v| v == true ? k.to_s : "#{k.to_s}=#{v.to_s}"}
response.headers["Cache-Control"] = cache_control.join(', ')
end
Defined in actionpack/lib/action_controller/base.rb line 1218
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionController::Base