protected Method

Base.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, :private => false
expires in 3.hours, 'max-stale' => 5.hours, :private => nil, :public => true

This method will overwrite an existing Cache-Control header. See www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more possibilities.

Source Code

# File action_controller/base.rb, line 1081
def expires_in(seconds, options = {}) #:doc:
  cache_options = { 'max-age' => seconds, 'private' => true }.symbolize_keys.merge!(options.symbolize_keys)
  cache_options.delete_if { |k,v| v.nil? or v == false }
  cache_control = cache_options.map{ |k,v| v == true ? k.to_s : "#{k.to_s}=#{v.to_s}"}
  response.headers["Cache-Control"] = cache_control.join(', ')
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.