mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Renamed LocalizedCache to DetailsCache.
This commit is contained in:
parent
9d7d6cd7ba
commit
df85ab41c1
8 changed files with 60 additions and 57 deletions
|
@ -267,7 +267,7 @@ module ActionMailer #:nodoc:
|
|||
|
||||
include AbstractController::Logger
|
||||
include AbstractController::Rendering
|
||||
include AbstractController::LocalizedCache
|
||||
include AbstractController::DetailsCache
|
||||
include AbstractController::Layouts
|
||||
include AbstractController::Helpers
|
||||
include AbstractController::Translation
|
||||
|
|
|
@ -13,9 +13,9 @@ module AbstractController
|
|||
autoload :Callbacks
|
||||
autoload :Collector
|
||||
autoload :Compatibility
|
||||
autoload :DetailsCache
|
||||
autoload :Helpers
|
||||
autoload :Layouts
|
||||
autoload :LocalizedCache
|
||||
autoload :Logger
|
||||
autoload :Rendering
|
||||
autoload :Translation
|
||||
|
|
48
actionpack/lib/abstract_controller/details_cache.rb
Normal file
48
actionpack/lib/abstract_controller/details_cache.rb
Normal file
|
@ -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
|
||||
"#<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
|
|
@ -1,49 +0,0 @@
|
|||
module AbstractController
|
||||
class HashKey
|
||||
@hash_keys = Hash.new {|h,k| h[k] = Hash.new {|sh,sk| sh[sk] = {} } }
|
||||
|
||||
def self.get(klass, formats, locale)
|
||||
@hash_keys[klass][formats][locale] ||= new(klass, formats, locale)
|
||||
end
|
||||
|
||||
attr_accessor :hash
|
||||
def initialize(klass, formats, locale)
|
||||
@formats, @locale = formats, locale
|
||||
@hash = [formats, locale].hash
|
||||
end
|
||||
|
||||
alias_method :eql?, :equal?
|
||||
|
||||
def inspect
|
||||
"#<HashKey -- formats: #{@formats.inspect} locale: #{@locale.inspect}>"
|
||||
end
|
||||
end
|
||||
|
||||
module LocalizedCache
|
||||
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(*args)
|
||||
Thread.current[:format_locale_key] = HashKey.get(self.class, formats, I18n.locale)
|
||||
super
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def with_template_cache(name)
|
||||
self.class.template_cache[Thread.current[:format_locale_key]][name] ||= super
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -165,13 +165,17 @@ module AbstractController
|
|||
|
||||
details = _normalize_details(options)
|
||||
|
||||
options[:_template] ||= with_template_cache(name) do
|
||||
options[:_template] ||= with_template_cache(name, details) do
|
||||
find_template(name, details, options)
|
||||
end
|
||||
end
|
||||
|
||||
def _details_defaults
|
||||
{ :formats => formats, :locale => [I18n.locale] }
|
||||
end
|
||||
|
||||
def _normalize_details(options)
|
||||
details = { :formats => formats }
|
||||
details = _details_defaults
|
||||
details[:formats] = Array(options[:format]) if options[:format]
|
||||
details[:locale] = Array(options[:locale]) if options[:locale]
|
||||
details
|
||||
|
@ -185,7 +189,7 @@ module AbstractController
|
|||
view_paths.exists?(name, details, options[:_prefix], options[:_partial])
|
||||
end
|
||||
|
||||
def with_template_cache(name)
|
||||
def with_template_cache(name, details)
|
||||
yield
|
||||
end
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ module ActionController
|
|||
|
||||
include ActionController::RackDelegation
|
||||
include AbstractController::Rendering
|
||||
include AbstractController::LocalizedCache
|
||||
include AbstractController::DetailsCache
|
||||
|
||||
def process_action(*)
|
||||
self.formats = request.formats.map {|x| x.to_sym }
|
||||
|
|
|
@ -196,7 +196,7 @@ module ActionView #:nodoc:
|
|||
# This is expensive, but we need to reset this when the format is updated,
|
||||
# which currently only happens
|
||||
Thread.current[:format_locale_key] =
|
||||
AbstractController::HashKey.get(self.class, formats, I18n.locale)
|
||||
AbstractController::HashKey.get(self.class, :formats => formats, :locale => [I18n.locale])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ module AbstractController
|
|||
|
||||
class CachedController < AbstractController::Base
|
||||
include AbstractController::Rendering
|
||||
include AbstractController::LocalizedCache
|
||||
include AbstractController::DetailsCache
|
||||
|
||||
self.view_paths = [ActionView::FixtureResolver.new(
|
||||
"default.erb" => "With Default",
|
Loading…
Reference in a new issue