Skip to content

Commit

Permalink
Modified caching implementation to work with NewBase
Browse files Browse the repository at this point in the history
  • Loading branch information
Yehuda Katz + Carl Lerche committed May 20, 2009
1 parent 0e7da0e commit 67cc021
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
22 changes: 19 additions & 3 deletions actionpack/lib/action_controller/caching/actions.rb
Expand Up @@ -61,8 +61,14 @@ def caches_action(*actions)
filter_options = { :only => actions, :if => options.delete(:if), :unless => options.delete(:unless) }

cache_filter = ActionCacheFilter.new(:layout => options.delete(:layout), :cache_path => options.delete(:cache_path), :store_options => options)
around_filter(filter_options) do |controller, action|
cache_filter.filter(controller, action)

# TODO: Remove this once new base is swapped in.
if defined?(Http)
around_filter cache_filter, filter_options
else
around_filter(filter_options) do |controller, action|
cache_filter.filter(controller, action)
end
end
end
end
Expand All @@ -85,14 +91,22 @@ def initialize(options, &block)
@options = options
end

# TODO: Remove once New Base is merged
def filter(controller, action)
should_continue = before(controller)
action.call if should_continue
after(controller)
end

def around_process_action(controller)
should_continue = before(controller)
yield if should_continue
after(controller)
end

def before(controller)
cache_path = ActionCachePath.new(controller, path_options_for(controller, @options.slice(:cache_path)))

if cache = controller.read_fragment(cache_path.path, @options[:store_options])
controller.rendered_action_cache = true
set_content_type!(controller, cache_path.extension)
Expand Down Expand Up @@ -129,7 +143,9 @@ def cache_layout?
end

def content_for_layout(controller)
controller.template.layout && controller.template.instance_variable_get('@cached_content_for_layout')
# TODO: Remove this when new base is merged in
template = controller.respond_to?(:template) ? controller.template : controller._action_view
template.layout && template.instance_variable_get('@cached_content_for_layout')
end
end

Expand Down
5 changes: 5 additions & 0 deletions actionpack/lib/action_controller/new_base/renderer.rb
Expand Up @@ -9,6 +9,11 @@ def initialize(*)
super
end

def response_body=(body)
response.body = body if response
super
end

def render_to_body(options)
_process_options(options)

Expand Down

0 comments on commit 67cc021

Please sign in to comment.