Module: ActionController::Caching::Pages::ClassMethods
- Defined in:
- lib/action_controller/caching.rb
Instance Method Summary collapse
-
#cache_page(content, path) ⇒ Object
Manually cache the
content
in the key determined bypath
. -
#caches_page(*actions) ⇒ Object
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. -
#expire_page(path) ⇒ Object
Expires the page that was cached with the
path
as a key.
Instance Method Details
#cache_page(content, path) ⇒ Object
Manually cache the content
in the key determined by path
. Example:
cache_page "I'm the cached content", "/lists/show"
75 76 77 78 79 80 |
# File 'lib/action_controller/caching.rb', line 75 def cache_page(content, path) return unless perform_caching FileUtils.makedirs(File.dirname(page_cache_path(path))) File.open(page_cache_path(path), "w+") { |f| f.write(content) } logger.info "Cached page: #{page_cache_file(path)}" unless logger.nil? end |
#caches_page(*actions) ⇒ Object
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.
84 85 86 87 88 89 |
# File 'lib/action_controller/caching.rb', line 84 def caches_page(*actions) return unless perform_caching actions.each do |action| class_eval "after_filter { |c| c.cache_page if c.action_name == '#{action}' }" end end |
#expire_page(path) ⇒ Object
Expires the page that was cached with the path
as a key. Example:
expire_page "/lists/show"
67 68 69 70 71 |
# File 'lib/action_controller/caching.rb', line 67 def expire_page(path) return unless perform_caching File.delete(page_cache_path(path)) if File.exists?(page_cache_path(path)) logger.info "Expired page: #{page_cache_file(path)}" unless logger.nil? end |