Module: Puppet::Util::Cacher::ClassMethods
- Defined in:
- lib/puppet/util/cacher.rb
Overview
Methods that can get added to a class.
Instance Method Summary collapse
- #attr_ttl(name) ⇒ Object
-
#cached_attr(name, options = {}, &block) ⇒ Object
Provide a means of defining an attribute whose value will be cached.
- #set_attr_ttl(name, value) ⇒ Object
Instance Method Details
#attr_ttl(name) ⇒ Object
62 63 64 65 |
# File 'lib/puppet/util/cacher.rb', line 62 def attr_ttl(name) return nil unless @attr_ttls @attr_ttls[name] end |
#cached_attr(name, options = {}, &block) ⇒ Object
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..
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/puppet/util/cacher.rb', line 43 def cached_attr(name, = {}, &block) init_method = "init_#{name}" define_method(init_method, &block) 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 { value_cache[name] = value } end if ttl = [:ttl] set_attr_ttl(name, ttl) end end |
#set_attr_ttl(name, value) ⇒ Object
67 68 69 70 |
# File 'lib/puppet/util/cacher.rb', line 67 def set_attr_ttl(name, value) @attr_ttls ||= {} @attr_ttls[name] = Integer(value) end |