Methods
Public Instance methods
Manually cache the content in the key determined by path. Example:
cache_page "I'm the cached content", "/lists/show"
[ show source ]
# File actionpack/lib/action_controller/caching/pages.rb, line 73 73: def cache_page(content, path) 74: return unless perform_caching 75: 76: benchmark "Cached page: #{page_cache_file(path)}" do 77: FileUtils.makedirs(File.dirname(page_cache_path(path))) 78: File.open(page_cache_path(path), "wb+") { |f| f.write(content) } 79: end 80: 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? }
[ show source ]
# File actionpack/lib/action_controller/caching/pages.rb, line 92 92: def caches_page(*actions) 93: return unless perform_caching 94: options = actions.extract_options! 95: after_filter({:only => actions}.merge(options)) { |c| c.cache_page } 96: end
Expires the page that was cached with the path as a key. Example:
expire_page "/lists/show"
[ show source ]
# File actionpack/lib/action_controller/caching/pages.rb, line 63 63: def expire_page(path) 64: return unless perform_caching 65: 66: benchmark "Expired page: #{page_cache_file(path)}" do 67: File.delete(page_cache_path(path)) if File.exist?(page_cache_path(path)) 68: end 69: end