Created — forked from neerajdotname/gist:160741

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:667647
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
def self.setup_rails_for_action_cache_options
::ActionController::Caching::Actions::ActionCacheFilter.class_eval do
def initialize(*actions, &block)
if [].respond_to?(:extract_options!)
@options = actions.extract_options!
@actions = actions.inject(@options.except(:cache_path)) do |hsh, action|
action.is_a?(Hash) ? hsh.merge(action) : hsh.merge(action => { :ttl => nil })
end
@options.slice!(:cache_path)
else
@actions = actions.inject({}) do |hsh, action|
action.is_a?(Hash) ? hsh.merge(action) : hsh.merge(action => { :ttl => nil })
end
end
end
 
 
def before(controller)
if !@actions.include?(controller.action_name.intern)
#return #this line has been commented out
end
 
if @options
action_cache_path = ActionController::Caching::Actions::ActionCachePath.new(controller, path_options_for(controller, @options))
else
action_cache_path = ActionController::Caching::Actions::ActionCachePath.new(controller)
end
 
#if conditional = @actions[controller.action_name.intern][:if] # existing code
conditional = @options[:if] # revised code
if conditional = @options[:if]
conditional = conditional.respond_to?(:call) ? conditional.call(controller) : controller.send(conditional)
end
@actions.delete(controller.action_name.intern) if conditional == false
 
tmp = action_cache_path.path
cache = controller.read_fragment(tmp)
if cache && (conditional || conditional.nil?)
controller.rendered_action_cache = true
if method(:set_content_type!).arity == 2
set_content_type!(controller, action_cache_path.extension)
else
set_content_type!(action_cache_path)
end
controller.send(:render, :text => cache)
false
else
controller.action_cache_path = action_cache_path if controller.respond_to? :action_cache_path
end
end
def after(controller)
puts 'after in plugin is called'
#return if !@actions.include?(controller.action_name.intern) || controller.rendered_action_cache # existing code
return if controller.rendered_action_cache || !caching_allowed(controller) # revised code
path = controller.respond_to?(:action_cache_path) ? controller.action_cache_path.path : ActionController::Caching::Actions::ActionCachePath.path_for(controller)
controller.write_fragment(path, controller.response.body, action_ttl(controller))
end
 
end
end
 
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.