Module: Merb::Caching::Actions

Action caching provides the ability to cache the output of individual actions. This output will be stored using fragment caching (Merb::Caching::Fragment). The output is stored based on a multipart key, which is comprised of the following pieces, in this order:

  • controller
  • action
  • parameters (represented as a list of parameter name/value pairs, sorted by name)

Examples

 class UserController < Merb::Controller
   cache_action(:show, :index)

   def show
      ... do some work to show a user ...
   end

   def index
      ... get the list of users ...
   end
 end

In this case, we would expect show to take an :id parameter, and index to take no parameters, so the fragment stored for this action will be represented thus:

  get :show, :id => 25    => [:user_controller, :show, :id, 25]
  get :index => [:user_controller, :index]

Action caches are expired based on the action alone (TODO: We need to modify expire action to allow expiration for specific parameter values).

  expire_action(:show)  => This will expire all cached show actions (i.e. All users, in this case)

Child modules and classes

Module Merb::Caching::Actions::ClassMethods

Public Instance Methods


expire_action (*actions)

Expire all cached content for the specific action, or array of actions.

    # File lib/merb/caching/action_cache.rb, line 54
54:       def expire_action(*actions)
55:         return unless _caching_enabled?        
56:         for action in [actions].flatten
57:           ::Merb::Caching::Fragment.expire_fragment(params_key(:action => action))
58:         end
59:       end