Module ActionController::Caching::Pages::ClassMethods
In: vendor/rails/actionpack/lib/action_controller/caching/pages.rb

Methods

Public Instance methods

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

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

[Source]

    # File vendor/rails/actionpack/lib/action_controller/caching/pages.rb, line 75
75:         def cache_page(content, path)
76:           return unless perform_caching
77: 
78:           benchmark "Cached page: #{page_cache_file(path)}" do
79:             FileUtils.makedirs(File.dirname(page_cache_path(path)))
80:             File.open(page_cache_path(path), "wb+") { |f| f.write(content) }
81:           end
82:         end

Caches the actions using the page-caching approach that‘ll store the cache in a path within the page_cache_directory that matches the triggering url.

Usage:

  # cache the index action
  caches_page :index

  # cache the index action except for JSON requests
  caches_page :index, :if => Proc.new { |c| !c.request.format.json? }

[Source]

    # File vendor/rails/actionpack/lib/action_controller/caching/pages.rb, line 94
94:         def caches_page(*actions)
95:           return unless perform_caching
96:           options = actions.extract_options!
97:           after_filter({:only => actions}.merge(options)) { |c| c.cache_page }
98:         end

Expires the page that was cached with the path as a key. Example:

  expire_page "/lists/show"

[Source]

    # File vendor/rails/actionpack/lib/action_controller/caching/pages.rb, line 65
65:         def expire_page(path)
66:           return unless perform_caching
67: 
68:           benchmark "Expired page: #{page_cache_file(path)}" do
69:             File.delete(page_cache_path(path)) if File.exist?(page_cache_path(path))
70:           end
71:         end

[Validate]