1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib/abstract_controller/details_cache.rb
2010-02-24 22:17:26 +01:00

48 lines
1 KiB
Ruby

module AbstractController
class HashKey
@hash_keys = Hash.new {|h,k| h[k] = {} }
def self.get(klass, details)
@hash_keys[klass][details] ||= new(klass, details)
end
attr_reader :hash
alias_method :eql?, :equal?
def initialize(klass, details)
@details, @hash = details, details.hash
end
def inspect
"#<HashKey -- details: #{@details.inspect}>"
end
end
module DetailsCache
extend ActiveSupport::Concern
module ClassMethods
def clear_template_caches!
ActionView::Partials::PartialRenderer::TEMPLATES.clear
template_cache.clear
super
end
def template_cache
@template_cache ||= Hash.new {|h,k| h[k] = {} }
end
end
def render_to_body(*args)
Thread.current[:format_locale_key] = HashKey.get(self.class, _details_defaults)
super
end
private
def with_template_cache(name, details)
self.class.template_cache[HashKey.get(self.class, details)][name] ||= super
end
end
end