diff options
author | Luke Kanies <luke@madstop.com> | 2008-11-11 13:12:21 -0800 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-11-11 13:12:21 -0800 |
commit | 0ecbf79faf8e69efda96f8611837cd1c395f7a7c (patch) | |
tree | 4fe918d384da032b797986c49f008548ce4e4795 /lib/puppet | |
parent | 29b97943e7efaad3cb3f8e7b82004c067d3fbf82 (diff) | |
download | puppet-0ecbf79faf8e69efda96f8611837cd1c395f7a7c.tar.gz puppet-0ecbf79faf8e69efda96f8611837cd1c395f7a7c.tar.xz puppet-0ecbf79faf8e69efda96f8611837cd1c395f7a7c.zip |
Adding cached attribute support to resources.
The Catalog is the expirer, which means that a resource
with no catalog will not cache data.
Also switching files to use a cached attribute for its stat.
And modifying catalogs to expire data at the end of every
transaction.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/node/catalog.rb | 6 | ||||
-rw-r--r-- | lib/puppet/type.rb | 8 | ||||
-rw-r--r-- | lib/puppet/type/file.rb | 20 |
3 files changed, 22 insertions, 12 deletions
diff --git a/lib/puppet/node/catalog.rb b/lib/puppet/node/catalog.rb index 8862d0cc9..a438a4764 100644 --- a/lib/puppet/node/catalog.rb +++ b/lib/puppet/node/catalog.rb @@ -2,6 +2,8 @@ require 'puppet/indirector' require 'puppet/simple_graph' require 'puppet/transaction' +require 'puppet/util/cacher' + require 'puppet/util/tagging' # This class models a node catalog. It is the thing @@ -15,6 +17,7 @@ class Puppet::Node::Catalog < Puppet::SimpleGraph indirects :catalog, :terminus_class => :compiler include Puppet::Util::Tagging + include Puppet::Util::Cacher::Expirer # The host name this is a catalog for. attr_accessor :name @@ -394,6 +397,9 @@ class Puppet::Node::Catalog < Puppet::SimpleGraph @transient_resources.clear @relationship_graph = nil end + + # Expire any cached data the resources are keeping. + expire() end # Verify that the given resource isn't defined elsewhere. diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index da274df88..1854c8801 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -10,6 +10,7 @@ require 'puppet/util/errors' require 'puppet/util/log_paths' require 'puppet/util/logging' require 'puppet/resource_reference' +require 'puppet/util/cacher' # see the bottom of the file for the rest of the inclusions @@ -19,6 +20,7 @@ class Type include Puppet::Util::Errors include Puppet::Util::LogPaths include Puppet::Util::Logging + include Puppet::Util::Cacher ############################### # Code related to resource type attributes. @@ -551,6 +553,12 @@ class Type } end + # Let the catalog determine whether a given cached value is + # still valid or has expired. + def expirer + catalog + end + # retrieve the 'should' value for a specified property def should(name) name = attr_alias(name) diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb index ccef61253..6eb7f62f5 100644 --- a/lib/puppet/type/file.rb +++ b/lib/puppet/type/file.rb @@ -734,7 +734,7 @@ module Puppet # use either 'stat' or 'lstat', and we expect the properties to use the # resulting stat object accordingly (mostly by testing the 'ftype' # value). - def stat(refresh = false) + cached_attr(:stat) do method = :stat # Files are the only types that support links @@ -743,18 +743,14 @@ module Puppet end path = self[:path] - if @stat.nil? or refresh == true - begin - @stat = File.send(method, self[:path]) - rescue Errno::ENOENT => error - return nil - rescue Errno::EACCES => error - warning "Could not stat; permission denied" - return nil - end + begin + File.send(method, self[:path]) + rescue Errno::ENOENT => error + return nil + rescue Errno::EACCES => error + warning "Could not stat; permission denied" + return nil end - - return @stat end # We have to hack this just a little bit, because otherwise we'll get |