Method: ActionController::Caching::Pages::ClassMethods#cache_page

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

#cache_page(content, path, extension = nil) ⇒ Object

Manually cache the content in the key determined by path. Example:

cache_page "I'm the cached content", "/lists/show"


74
75
76
77
78
79
80
81
82
# File 'lib/action_controller/caching/pages.rb', line 74

def cache_page(content, path, extension = nil)
  return unless perform_caching
  path = page_cache_path(path, extension)

  instrument_page_cache :write_page, path do
    FileUtils.makedirs(File.dirname(path))
    File.open(path, "wb+") { |f| f.write(content) }
  end
end