diff options
| author | Luke Kanies <luke@madstop.com> | 2008-11-11 13:31:31 -0800 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2008-11-11 13:31:31 -0800 |
| commit | 73fa3977d7274f1c54c89971c0389f9a9f980c9a (patch) | |
| tree | 2bd9e0d412ea7a321d21fa6f45a016991486af7c /lib | |
| parent | 0ecbf79faf8e69efda96f8611837cd1c395f7a7c (diff) | |
| download | puppet-73fa3977d7274f1c54c89971c0389f9a9f980c9a.tar.gz puppet-73fa3977d7274f1c54c89971c0389f9a9f980c9a.tar.xz puppet-73fa3977d7274f1c54c89971c0389f9a9f980c9a.zip | |
Adding caching support to parameters, and using cached attributes for file source and metadata.
As hoped, this drastically simplifies the code around retaining
this data.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/parameter.rb | 6 | ||||
| -rwxr-xr-x | lib/puppet/type/file/source.rb | 45 | ||||
| -rw-r--r-- | lib/puppet/util/cacher.rb | 6 |
3 files changed, 29 insertions, 28 deletions
diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb index f82438903..5f68d44a5 100644 --- a/lib/puppet/parameter.rb +++ b/lib/puppet/parameter.rb @@ -2,6 +2,7 @@ require 'puppet/util/methodhelper' require 'puppet/util/log_paths' require 'puppet/util/logging' require 'puppet/util/docs' +require 'puppet/util/cacher' class Puppet::Parameter include Puppet::Util @@ -9,6 +10,7 @@ class Puppet::Parameter include Puppet::Util::LogPaths include Puppet::Util::Logging include Puppet::Util::MethodHelper + include Puppet::Util::Cacher # A collection of values and regexes, used for specifying # what values are allowed in a given parameter. @@ -354,6 +356,10 @@ class Puppet::Parameter self.fail(Puppet::DevError, msg) end + def expirer + resource.catalog + end + def fail(*args) type = nil if args[0].is_a?(Class) diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb index ba5fcbd0e..4e67b1a8b 100755 --- a/lib/puppet/type/file/source.rb +++ b/lib/puppet/type/file/source.rb @@ -101,16 +101,13 @@ module Puppet end # Look up (if necessary) and return remote content. - def content + cached_attr(:content) do raise Puppet::DevError, "No source for content was stored with the metadata" unless metadata.source - unless defined?(@content) and @content - unless tmp = Puppet::FileServing::Content.find(metadata.source) - fail "Could not find any content at %s" % metadata.source - end - @content = tmp.content + unless tmp = Puppet::FileServing::Content.find(metadata.source) + fail "Could not find any content at %s" % metadata.source end - @content + tmp.content end # Copy the values from the source to the resource. Yay. @@ -135,12 +132,6 @@ module Puppet end end - # Remove any temporary attributes we manage. - def flush - @metadata = nil - @content = nil - end - def pinparams [:mode, :type, :owner, :group, :content] end @@ -152,24 +143,22 @@ module Puppet # Provide, and retrieve if necessary, the metadata for this file. Fail # if we can't find data about this host, and fail if there are any # problems in our query. - attr_writer :metadata - def metadata - unless defined?(@metadata) and @metadata - return @metadata = nil unless value - value.each do |source| - begin - if data = Puppet::FileServing::Metadata.find(source) - @metadata = data - @metadata.source = source - break - end - rescue => detail - fail detail, "Could not retrieve file metadata for %s: %s" % [source, detail] + cached_attr(:metadata) do + return nil unless value + result = nil + value.each do |source| + begin + if data = Puppet::FileServing::Metadata.find(source) + result = data + result.source = source + break end + rescue => detail + fail detail, "Could not retrieve file metadata for %s: %s" % [source, detail] end - fail "Could not retrieve information from source(s) %s" % value.join(", ") unless @metadata end - return @metadata + fail "Could not retrieve information from source(s) %s" % value.join(", ") unless result + result end # Make sure we're also checking the checksum diff --git a/lib/puppet/util/cacher.rb b/lib/puppet/util/cacher.rb index af5c5ebfc..c1b3bad7a 100644 --- a/lib/puppet/util/cacher.rb +++ b/lib/puppet/util/cacher.rb @@ -47,6 +47,12 @@ module Puppet::Util::Cacher define_method(name) do cached_value(name) end + + define_method(name.to_s + "=") do |value| + # Make sure the cache timestamp is set + cache_timestamp + value_cache[name] = value + end end end |
