Module: Merb::Cache::ControllerClassMethods
- Included in:
- Merb::Controller
- Defined in:
- lib/merb-cache/cache-action.rb,
lib/merb-cache/cache-page.rb
Instance Method Summary collapse
-
#cache_action(action, from_now = nil, opts = {}) ⇒ Object
Register the action for action caching.
-
#cache_actions(*actions) ⇒ Object
Register actions for action caching (before and after filters).
-
#cache_page(action, from_now = nil) ⇒ Object
Register the action for page caching.
-
#cache_pages(*pages) ⇒ Object
Register actions for page caching (before and after filters).
Instance Method Details
#cache_action(action, from_now = nil, opts = {}) ⇒ Object
Register the action for action caching
Parameters
- action<Symbol>
-
The name of the action to register
- from_now<~minutes>
-
The number of minutes (from now) the cache should persist
Examples
cache_action :mostly_static
cache_action :barely_dynamic, 10
19 20 21 |
# File 'lib/merb-cache/cache-action.rb', line 19 def cache_action(action, from_now = nil, opts = {}) cache_actions([action, from_now, opts]) end |
#cache_actions(*actions) ⇒ Object
Register actions for action caching (before and after filters)
Parameter
- actions<Symbol,Array>
-
See #cache_action
Example
cache_actions :mostly_static, [:barely_dynamic, 10]
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/merb-cache/cache-action.rb', line 30 def cache_actions(*actions) actions.each do |action, from_now, opts| from_now, opts = nil, from_now if Hash === from_now before("cache_#{action}_before", opts.merge(:only => action)) after("cache_#{action}_after", opts.merge(:only => action)) alias_method "cache_#{action}_before", :cache_action_before alias_method "cache_#{action}_after", :cache_action_after _actions = Merb::Cache.cached_actions[controller_name] ||= {} _actions[action] = from_now end true end |
#cache_page(action, from_now = nil) ⇒ Object
Register the action for page caching
Parameters
- action<Symbol>
-
The name of the action to register
- from_now<~minutes>
-
The number of minutes (from now) the cache should persist
Examples
cache_page :mostly_static
cache_page :barely_dynamic, 10
20 21 22 |
# File 'lib/merb-cache/cache-page.rb', line 20 def cache_page(action, from_now = nil) cache_pages([action, from_now]) end |
#cache_pages(*pages) ⇒ Object
Register actions for page caching (before and after filters)
Parameter
- pages<Symbol,Array>
-
See #cache_page
Example
cache_pages :mostly_static, [:barely_dynamic, 10]
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/merb-cache/cache-page.rb', line 31 def cache_pages(*pages) if pages.any? && !Merb::Cache.cached_pages.key?(controller_name) before(:cache_page_before) after(:cache_page_after) end pages.each do |action, from_now| _pages = Merb::Cache.cached_pages[controller_name] ||= {} _pages[action] = [from_now, 0] end true end |