module ActionController::Caching::Pages::ClassMethods
def cache_page(content, path)
Manually cache the +content+ in the key determined by +path+. Example:
def cache_page(content, path) return unless perform_caching benchmark "Cached page: #{page_cache_file(path)}" do FileUtils.makedirs(File.dirname(page_cache_path(path))) File.open(page_cache_path(path), "wb+") { |f| f.write(content) } end end
def caches_page(*actions)
# cache the index action except for JSON requests
caches_page :index
# cache the index action
Usage:
matches the triggering url.
Caches the +actions+ using the page-caching approach that'll store the cache in a path within the page_cache_directory that
def caches_page(*actions) return unless perform_caching options = actions.extract_options! after_filter({:only => actions}.merge(options)) { |c| c.cache_page } end
def expire_page(path)
Expires the page that was cached with the +path+ as a key. Example:
def expire_page(path) return unless perform_caching benchmark "Expired page: #{page_cache_file(path)}" do File.delete(page_cache_path(path)) if File.exist?(page_cache_path(path)) end end
def page_cache_file(path)
def page_cache_file(path) name = (path.empty? || path == "/") ? "/index" : URI.unescape(path.chomp('/')) name << page_cache_extension unless (name.split('/').last || name).include? '.' return name end
def page_cache_path(path)
def page_cache_path(path) page_cache_directory + page_cache_file(path) end