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

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(options, &block) ⇒ ActionCacheFilter

Returns a new instance of ActionCacheFilter.



149
150
151
152
# File 'lib/action_controller/caching/actions.rb', line 149

def initialize(options, &block)
  @cache_path, @store_options, @cache_layout =
    options.values_at(:cache_path, :store_options, :layout)
end

Instance Method Details

#around(controller) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/action_controller/caching/actions.rb', line 154

def around(controller)
  cache_layout = expand_option(controller, @cache_layout)
  path_options = expand_option(controller, @cache_path)
  cache_path = ActionCachePath.new(controller, path_options || {})

  body = controller.read_fragment(cache_path.path, @store_options)

  unless body
    controller.action_has_layout = false unless cache_layout
    yield
    controller.action_has_layout = true
    body = controller._save_fragment(cache_path.path, @store_options)
  end

  body = render_to_string(controller, body) unless cache_layout

  controller.response_body = body
  controller.content_type = Mime[cache_path.extension || :html]
end

#render_to_string(controller, body) ⇒ Object



175
176
177
# File 'lib/action_controller/caching/actions.rb', line 175

def render_to_string(controller, body)
  controller.render_to_string(text: body, layout: true)
end