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) ⇒ ActionCacheFilter

Returns a new instance of ActionCacheFilter.



200
201
202
# File 'lib/action_controller/caching.rb', line 200

def initialize(*actions)
  @actions = Set.new actions
end

Instance Method Details

#after(controller) ⇒ Object



217
218
219
220
# File 'lib/action_controller/caching.rb', line 217

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

#before(controller) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/action_controller/caching.rb', line 204

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