diff options
author | Luke Kanies <luke@madstop.com> | 2007-08-15 17:18:43 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2007-08-15 17:18:43 -0500 |
commit | 1527f4a615f9c429e90becd90f9ed1e8c1e83249 (patch) | |
tree | 87656fd11245e4e00605eac7cb20fe8cd8367338 /lib/puppet | |
parent | a9539548d957304a03aa8bdc61c06793228f57c0 (diff) | |
download | puppet-1527f4a615f9c429e90becd90f9ed1e8c1e83249.tar.gz puppet-1527f4a615f9c429e90becd90f9ed1e8c1e83249.tar.xz puppet-1527f4a615f9c429e90becd90f9ed1e8c1e83249.zip |
Adding node caching, so that node sources are not spammed during file serving and such
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/network/handler/node.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/puppet/network/handler/node.rb b/lib/puppet/network/handler/node.rb index cf39d630b..0d685b1f1 100644 --- a/lib/puppet/network/handler/node.rb +++ b/lib/puppet/network/handler/node.rb @@ -10,6 +10,7 @@ class Puppet::Network::Handler::Node < Puppet::Network::Handler # A simplistic class for managing the node information itself. class SimpleNode attr_accessor :name, :classes, :parameters, :environment, :source, :ipaddress, :names + attr_reader :time def initialize(name, options = {}) @name = name @@ -31,6 +32,8 @@ class Puppet::Network::Handler::Node < Puppet::Network::Handler @environment = env end end + + @time = Time.now end # Merge the node facts with parameters from the node source. @@ -168,6 +171,9 @@ class Puppet::Network::Handler::Node < Puppet::Network::Handler extend(mod) super + + # We cache node info for speed + @node_cache = {} end # Try to retrieve a given node's parameters. @@ -181,6 +187,23 @@ class Puppet::Network::Handler::Node < Puppet::Network::Handler private + # Store the node to make things a bit faster. + def cache(node) + @node_cache[node.name] = node + end + + # If the node is cached, return it. + def cached?(name) + # Don't use cache when the filetimeout is set to 0 + return false if [0, "0"].include?(Puppet[:filetimeout]) + + if node = @node_cache[name] and Time.now - node.time < Puppet[:filetimeout] + return node + else + return false + end + end + # Create/cache a fact handler. def fact_handler unless defined?(@fact_handler) |