Methods that can get added to a class.
# File lib/puppet/util/cacher.rb, line 43 def attr_ttl(name) @attr_ttls[name] end
Provide a means of defining an attribute whose value will be cached. Must provide a block capable of defining the value if it’s flushed..
# File lib/puppet/util/cacher.rb, line 24 def cached_attr(name, ttl, &block) init_method = "init_#{name}" define_method(init_method, &block) set_attr_ttl(name, ttl) define_method(name) do cached_value(name) end define_method(name.to_s + "=") do |value| # Make sure the cache timestamp is set value_cache.synchronize do value_cache[name] = value set_expiration(name) end end end
# File lib/puppet/util/cacher.rb, line 47 def set_attr_ttl(name, value) @attr_ttls ||= {} @attr_ttls[name] = Integer(value) end