Class: ActionController::Caching::Actions::ActionCacheFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/action_controller/caching.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(*actions, &block) ⇒ ActionCacheFilter

Returns a new instance of ActionCacheFilter.



229
230
231
232
# File 'lib/action_controller/caching.rb', line 229

def initialize(*actions, &block)
  @options = actions.extract_options!
  @actions = Set.new actions
end

Instance Method Details

#after(controller) ⇒ Object



247
248
249
250
# File 'lib/action_controller/caching.rb', line 247

def after(controller)
  return if !@actions.include?(controller.action_name.intern) || controller.rendered_action_cache || !caching_allowed(controller)
  controller.write_fragment(controller.action_cache_path.path, controller.response.body)
end

#before(controller) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/action_controller/caching.rb', line 234

def before(controller)
  return unless @actions.include?(controller.action_name.intern)
  cache_path = ActionCachePath.new(controller, path_options_for(controller, @options))
  if cache = controller.read_fragment(cache_path.path)
    controller.rendered_action_cache = true
    set_content_type!(controller, cache_path.extension)
    controller.send!(:render_for_text, cache)
    false
  else
    controller.action_cache_path = cache_path
  end
end