module Chef::Node::Mixin::DeepMergeCache
Attributes
deep_merge_cache[RW]
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.
Public Class Methods
new()
click to toggle source
# 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 = {} end
Public Instance Methods
[](key)
click to toggle source
# 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[key.to_s] = merged_attributes(key) end ret = ret.call while ret.is_a?(::Chef::DelayedEvaluator) ret end
reset_cache(path = nil)
click to toggle source
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['bar’]= 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.
# File lib/chef/node/mixin/deep_merge_cache.rb, line 40 def reset_cache(path = nil) if path.nil? deep_merge_cache.clear else deep_merge_cache.delete(path.to_s) end end
Also aliased as: reset