From df85ab41c1ff6992dd462a0e63dac9dcdcee0348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 24 Feb 2010 22:06:24 +0100 Subject: Renamed LocalizedCache to DetailsCache. --- .../lib/abstract_controller/details_cache.rb | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 actionpack/lib/abstract_controller/details_cache.rb (limited to 'actionpack/lib/abstract_controller/details_cache.rb') diff --git a/actionpack/lib/abstract_controller/details_cache.rb b/actionpack/lib/abstract_controller/details_cache.rb new file mode 100644 index 0000000000..5b87b41e7d --- /dev/null +++ b/actionpack/lib/abstract_controller/details_cache.rb @@ -0,0 +1,48 @@ +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 + "#" + 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 -- cgit v1.2.3