Module: Puppet::Util::Cacher::ClassMethods
- Defined in:
- lib/vendor/puppet/util/cacher.rb
Overview
Methods that can get added to a class.
Instance Method Summary collapse
- #attr_ttl(name) ⇒ Object
-
#cached_attr(name, ttl, &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
43 44 45 |
# File 'lib/vendor/puppet/util/cacher.rb', line 43 def attr_ttl(name) @attr_ttls[name] end |
#cached_attr(name, ttl, &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..
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vendor/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 |
#set_attr_ttl(name, value) ⇒ Object
47 48 49 50 |
# File 'lib/vendor/puppet/util/cacher.rb', line 47 def set_attr_ttl(name, value) @attr_ttls ||= {} @attr_ttls[name] = Integer(value) end |