Method: ActionController::Caching::Pages#cache_page

Defined in:
lib/action_controller/caching/pages.rb

#cache_page(content = nil, options = nil) ⇒ Object

Manually cache the content in the key determined by options. If no content is provided, the contents of response.body is used If no options are provided, the requested url is used. Example:

cache_page "I'm the cached content", :controller => "lists", :action => "show"


139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/action_controller/caching/pages.rb', line 139

def cache_page(content = nil, options = nil)
  return unless self.class.perform_caching && caching_allowed

  path = case options
    when Hash
      url_for(options.merge(:only_path => true, :format => params[:format]))
    when String
      options
    else
      request.path
  end


  if (type = Mime::LOOKUP[self.content_type]) && (type_symbol = type.symbol).present?
    extension = ".#{type_symbol}"
  end

  self.class.cache_page(content || response.body, path, extension)
end