diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2019-02-07 13:30:58 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2019-02-08 15:13:09 -0800 |
commit | 6124eb02c63b666e640e778bf74380c3772926a0 (patch) | |
tree | 442354e5c605c63a6492efe59a1b09ec9bfa07d1 /actionview | |
parent | b67d5c6dedbf033515a96a95d24d085bf99a0d07 (diff) | |
download | rails-6124eb02c63b666e640e778bf74380c3772926a0.tar.gz rails-6124eb02c63b666e640e778bf74380c3772926a0.tar.bz2 rails-6124eb02c63b666e640e778bf74380c3772926a0.zip |
Split digest cache from details identity cache
This commit splits the digest cache from the "details identity" cache.
Now both caches can be managed independently.
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/lib/action_view/lookup_context.rb | 29 | ||||
-rw-r--r-- | actionview/lib/action_view/rendering.rb | 1 | ||||
-rw-r--r-- | actionview/test/template/resolver_cache_test.rb | 1 | ||||
-rw-r--r-- | actionview/test/template/test_case_test.rb | 4 |
4 files changed, 27 insertions, 8 deletions
diff --git a/actionview/lib/action_view/lookup_context.rb b/actionview/lib/action_view/lookup_context.rb index c3bb0a49fc..0387fd0e83 100644 --- a/actionview/lib/action_view/lookup_context.rb +++ b/actionview/lib/action_view/lookup_context.rb @@ -55,25 +55,36 @@ module ActionView register_detail(:handlers) { Template::Handlers.extensions } class DetailsKey #:nodoc: + alias :eql? :equal? @details_keys = Concurrent::Map.new + @digest_cache = Concurrent::Map.new + + def self.digest_cache(details) + if details[:formats] + details = details.dup + details[:formats] &= Template::Types.symbols + end + @digest_cache[details] ||= Concurrent::Map.new + end - def self.get(details) + def self.details_cache_key(details) if details[:formats] details = details.dup details[:formats] &= Template::Types.symbols end - @details_keys[details] ||= Concurrent::Map.new + @details_keys[details] ||= Object.new end def self.clear @view_context_class = nil @details_keys.clear + @digest_cache.clear end def self.digest_caches - @details_keys.values + @digest_cache.values end def self.view_context_class(klass) @@ -88,7 +99,7 @@ module ActionView # Calculate the details key. Remove the handlers from calculation to improve performance # since the user cannot modify it explicitly. def details_key #:nodoc: - @details_key ||= DetailsKey.get(@details) if @cache + @details_key ||= DetailsKey.details_cache_key(@details) if @cache end # Temporary skip passing the details_key forward. @@ -102,7 +113,8 @@ module ActionView private def _set_detail(key, value) # :doc: - @details = @details.dup if @details_key + @details = @details.dup if @digest_cache || @details_key + @digest_cache = nil @details_key = nil @details[key] = value end @@ -178,7 +190,7 @@ module ActionView user_details = @details.merge(options) if @cache - details_key = DetailsKey.get(user_details) + details_key = DetailsKey.details_cache_key(user_details) else details_key = nil end @@ -205,7 +217,7 @@ module ActionView end if @cache - [details, DetailsKey.get(details)] + [details, DetailsKey.details_cache_key(details)] else [details, nil] end @@ -236,6 +248,7 @@ module ActionView def initialize(view_paths, details = {}, prefixes = []) @details_key = nil + @digest_cache = nil @cache = true @prefixes = prefixes @rendered_format = nil @@ -245,7 +258,7 @@ module ActionView end def digest_cache - details_key + @digest_cache ||= DetailsKey.digest_cache(@details) end def initialize_details(target, details) diff --git a/actionview/lib/action_view/rendering.rb b/actionview/lib/action_view/rendering.rb index cf7d1105e0..da92ce1f5e 100644 --- a/actionview/lib/action_view/rendering.rb +++ b/actionview/lib/action_view/rendering.rb @@ -87,6 +87,7 @@ module ActionView # Returns an object that is able to render templates. def view_renderer # :nodoc: + # Lifespan: Per controller @_view_renderer ||= ActionView::Renderer.new(lookup_context) end diff --git a/actionview/test/template/resolver_cache_test.rb b/actionview/test/template/resolver_cache_test.rb index 8a5db1346a..90b61a2aa1 100644 --- a/actionview/test/template/resolver_cache_test.rb +++ b/actionview/test/template/resolver_cache_test.rb @@ -4,6 +4,7 @@ require "abstract_unit" class ResolverCacheTest < ActiveSupport::TestCase def test_inspect_shields_cache_internals + ActionView::LookupContext::DetailsKey.clear assert_match %r(#<ActionView::Resolver:0x[0-9a-f]+ @cache=#<ActionView::Resolver::Cache:0x[0-9a-f]+ keys=0 queries=0>>), ActionView::Resolver.new.inspect end end diff --git a/actionview/test/template/test_case_test.rb b/actionview/test/template/test_case_test.rb index ab3ababba4..4d3338e637 100644 --- a/actionview/test/template/test_case_test.rb +++ b/actionview/test/template/test_case_test.rb @@ -24,6 +24,10 @@ module ActionView DeveloperStruct = Struct.new(:name) module SharedTests + def setup + ActionView::LookupContext::DetailsKey.clear + end + def self.included(test_case) test_case.class_eval do test "helpers defined on ActionView::TestCase are available" do |