Class: ActionView::Resolver::Cache
- Defined in:
- actionview/lib/action_view/template/resolver.rb
Overview
Threadsafe template cache
Defined Under Namespace
Classes: SmallCache
Constant Summary collapse
- PARTIAL_BLOCK =
Preallocate all the default blocks for performance/memory consumption reasons
lambda { |cache, partial| cache[partial] = SmallCache.new }
- PREFIX_BLOCK =
lambda { |cache, prefix| cache[prefix] = SmallCache.new(&PARTIAL_BLOCK) }
- NAME_BLOCK =
lambda { |cache, name| cache[name] = SmallCache.new(&PREFIX_BLOCK) }
- KEY_BLOCK =
lambda { |cache, key| cache[key] = SmallCache.new(&NAME_BLOCK) }
- NO_TEMPLATES =
Usually a majority of template look ups return nothing, use this canonical preallocated array to save memory
[].freeze
Instance Method Summary collapse
-
#cache(key, name, prefix, partial, locals) ⇒ Object
Cache the templates returned by the block.
-
#cache_query(query) ⇒ Object
:nodoc:.
- #clear ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #inspect ⇒ Object
-
#size ⇒ Object
Get the cache size.
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
55 56 57 58 |
# File 'actionview/lib/action_view/template/resolver.rb', line 55 def initialize @data = SmallCache.new(&KEY_BLOCK) @query_cache = SmallCache.new end |
Instance Method Details
#cache(key, name, prefix, partial, locals) ⇒ Object
Cache the templates returned by the block
65 66 67 |
# File 'actionview/lib/action_view/template/resolver.rb', line 65 def cache(key, name, prefix, partial, locals) @data[key][name][prefix][partial][locals] ||= canonical_no_templates(yield) end |
#cache_query(query) ⇒ Object
:nodoc:
69 70 71 |
# File 'actionview/lib/action_view/template/resolver.rb', line 69 def cache_query(query) # :nodoc: @query_cache[query] ||= canonical_no_templates(yield) end |
#clear ⇒ Object
73 74 75 76 |
# File 'actionview/lib/action_view/template/resolver.rb', line 73 def clear @data.clear @query_cache.clear end |
#inspect ⇒ Object
60 61 62 |
# File 'actionview/lib/action_view/template/resolver.rb', line 60 def inspect "#{to_s[0..-2]} keys=#{@data.size} queries=#{@query_cache.size}>" end |
#size ⇒ Object
Get the cache size. Do not call this method. This method is not guaranteed to be here ever.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'actionview/lib/action_view/template/resolver.rb', line 80 def size # :nodoc: size = 0 @data.each_value do |v1| v1.each_value do |v2| v2.each_value do |v3| v3.each_value do |v4| size += v4.size end end end end size + @query_cache.size end |