diff options
| author | Luke Kanies <luke@madstop.com> | 2008-05-13 16:00:58 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-05-13 16:00:58 -0500 |
| commit | 6efe4000dda3379e867786a9c2d4ae0f0cdfc3be (patch) | |
| tree | a16fd1ae1f4aab7fe04af88daa78f1be1a2b1f3e /lib/puppet/util | |
| parent | 68d8d0ae0686939d94dae8ccc70e5582187335dc (diff) | |
| download | puppet-6efe4000dda3379e867786a9c2d4ae0f0cdfc3be.tar.gz puppet-6efe4000dda3379e867786a9c2d4ae0f0cdfc3be.tar.xz puppet-6efe4000dda3379e867786a9c2d4ae0f0cdfc3be.zip | |
Using the new Cacher class for handling cached data.
This provides a single, global bit for determining whether
a given piece of cached data is still valid.
Diffstat (limited to 'lib/puppet/util')
| -rw-r--r-- | lib/puppet/util/cacher.rb | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/puppet/util/cacher.rb b/lib/puppet/util/cacher.rb index fbab9ab42..7b352c72a 100644 --- a/lib/puppet/util/cacher.rb +++ b/lib/puppet/util/cacher.rb @@ -26,7 +26,7 @@ module Puppet::Util::Cacher def cached_attr(name, &block) define_method(name) do - cache(name, &block) + attr_cache(name, &block) end end end @@ -34,7 +34,7 @@ module Puppet::Util::Cacher module InstanceMethods private - def cache(name, &block) + def attr_cache(name, &block) unless defined?(@cacher_caches) and @cacher_caches @cacher_caches = Cache.new end @@ -44,24 +44,26 @@ module Puppet::Util::Cacher end class Cache - attr_reader :timestamp, :caches + attr_accessor :caches, :timestamp def initialize - @timestamp = Time.now @caches = {} end def value(name) raise ArgumentError, "You must provide a block when using the cache" unless block_given? - @caches.clear unless Puppet::Util::Cacher.valid?(@timestamp) + if timestamp.nil? or ! Puppet::Util::Cacher.valid?(timestamp) + caches.clear + self.timestamp = Time.now + end # Use 'include?' here rather than testing for truth, so we # can cache false values. - unless @caches.include?(name) - @caches[name] = yield + unless caches.include?(name) + caches[name] = yield end - @caches[name] + caches[name] end end end |
