Module: Chef::Node::Mixin::DeepMergeCache

Included in:
Attribute
Defined in:
lib/chef/node/mixin/deep_merge_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#deep_merge_cacheObject

Cache of deep merged values by top-level key. This is a simple hash which has keys that are the top-level keys of the node object, and we save the computed deep-merge for that key here. There is no cache of subtrees.



27
28
29
# File 'lib/chef/node/mixin/deep_merge_cache.rb', line 27

def deep_merge_cache
  @deep_merge_cache
end

Instance Method Details

#[](key) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/chef/node/mixin/deep_merge_cache.rb', line 50

def [](key)
  ret = if deep_merge_cache.key?(key.to_s)
          # return the cache of the deep merged values by top-level key
          deep_merge_cache[key.to_s]
        else
          # save all the work of computing node[key]
          deep_merge_cache.internal_set(key.to_s, merged_attributes(key))
        end
  ret = ret.call while ret.is_a?(::Chef::DelayedEvaluator)
  ret
end

#initializeObject



29
30
31
32
33
34
# File 'lib/chef/node/mixin/deep_merge_cache.rb', line 29

def initialize
  @merged_attributes = nil
  @combined_override = nil
  @combined_default = nil
  @deep_merge_cache = Chef::Node::ImmutableMash.new
end

#reset_cache(path = nil) ⇒ Object Also known as: reset

Invalidate a key in the deep_merge_cache. If called with nil, or no arg, this will invalidate the entire deep_merge cache. In the case of the user doing node.default['foo']['bar']['baz']= that eventually results in a call to reset_cache('foo') here. A node.default=hash_thing call must invalidate the entire cache and re-deep-merge the entire node object.



40
41
42
43
44
45
46
# File 'lib/chef/node/mixin/deep_merge_cache.rb', line 40

def reset_cache(path = nil)
  if path.nil?
    deep_merge_cache.regular_clear
  else
    deep_merge_cache.regular_delete(path.to_s)
  end
end