Module: RocketPants::Caching::ClassMethods

Defined in:
lib/rocket_pants/controller/caching.rb

Instance Method Summary collapse

Instance Method Details

#caches(*args) ⇒ Object

Sets up automatic etag and cache control headers for api resource controllers using an after filter. Note that for the middleware to actually be inserted, ‘RocketPants.enable_caching` needs to be set to true.

Examples:

Setting up caching on a series of actions

caches :index, :show

Setting up caching with options

caches :index, :show, :cache_for => 3.minutes

Parameters:

  • args (Symbol*)

    a collection of action names to perform caching on.

  • options (Hash)

    options to configure caching



94
95
96
97
98
99
100
101
102
103
# File 'lib/rocket_pants/controller/caching.rb', line 94

def caches(*args)
  options     = args.extract_options!
  self.cached_actions += Array.wrap(args).map(&:to_s).compact
  # Setup the time based caching.
  if options.has_key?(:cache_for)
    self.caching_timeout = options.delete(:cache_for)
  end
  # Merge in any caching options for other controllers.
  caching_options.merge!(options.delete(:caching_options) || {})
end