Manually cache the content in the key determined by path. Example:
cache_page "I'm the cached content", "/lists/show"
# File lib/action_controller/caching/pages.rb, line 74
74: def cache_page(content, path)
75: return unless perform_caching
76: path = page_cache_path(path)
77:
78: instrument_page_cache :write_page, path do
79: FileUtils.makedirs(File.dirname(path))
80: File.open(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? }
# File 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"
# File lib/action_controller/caching/pages.rb, line 63
63: def expire_page(path)
64: return unless perform_caching
65: path = page_cache_path(path)
66:
67: instrument_page_cache :expire_page, path do
68: File.delete(path) if File.exist?(path)
69: end
70: end
# File lib/action_controller/caching/pages.rb, line 111
111: def instrument_page_cache(name, path)
112: ActiveSupport::Notifications.instrument("#{name}.action_controller", :path => path){ yield }
113: end
# File lib/action_controller/caching/pages.rb, line 101
101: def page_cache_file(path)
102: name = (path.empty? || path == "/") ? "/index" : URI.unescape(path.chomp('/'))
103: name << page_cache_extension unless (name.split('/').last || name).include? '.'
104: return name
105: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.