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/network | |
| 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/network')
| -rw-r--r-- | lib/puppet/network/http_pool.rb | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/lib/puppet/network/http_pool.rb b/lib/puppet/network/http_pool.rb index cf17a8380..78a35cc15 100644 --- a/lib/puppet/network/http_pool.rb +++ b/lib/puppet/network/http_pool.rb @@ -1,10 +1,13 @@ require 'puppet/ssl/host' require 'net/https' +require 'puppet/util/cacher' module Puppet::Network; end # Manage Net::HTTP instances for keep-alive. module Puppet::Network::HttpPool + extend Puppet::Util::Cacher + # 2008/03/23 # LAK:WARNING: Enabling this has a high propability of # causing corrupt files and who knows what else. See #1010. @@ -17,23 +20,15 @@ module Puppet::Network::HttpPool # Create an ssl host instance for getting certificate # information. def self.ssl_host - unless defined?(@ssl_host) and @ssl_host - @ssl_host = Puppet::SSL::Host.new - end - @ssl_host + attr_cache(:ssl_host) { Puppet::SSL::Host.new } end - @http_cache = {} - # Clear our http cache, closing all connections. def self.clear_http_instances - @http_cache.each do |name, connection| + http_cache.each do |name, connection| connection.finish if connection.started? end - @http_cache.clear - @cert = nil - @key = nil - @ssl_host = nil + Puppet::Util::Cacher.invalidate end # Make sure we set the driver up when we read the cert in. @@ -69,11 +64,11 @@ module Puppet::Network::HttpPool # Return our cached instance if we've got a cache, as long as we're not # resetting the instance. if keep_alive? - return @http_cache[key] if ! reset and @http_cache[key] + return http_cache[key] if ! reset and http_cache[key] # Clean up old connections if we have them. - if http = @http_cache[key] - @http_cache.delete(key) + if http = http_cache[key] + http_cache.delete(key) http.finish if http.started? end end @@ -103,8 +98,15 @@ module Puppet::Network::HttpPool cert_setup(http) - @http_cache[key] = http if keep_alive? + http_cache[key] = http if keep_alive? return http end + + private + + def self.http_cache + # Default to an empty hash. + attr_cache(:http) { Hash.new } + end end |
