diff options
| author | Luke Kanies <luke@madstop.com> | 2007-09-25 15:52:26 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-09-25 15:52:26 -0500 |
| commit | 938b91894d09ea804d2fc9eaac57b52f46de793a (patch) | |
| tree | 932455f303de4f4ed3435b301ea949e7f1e9babb /lib | |
| parent | 8ec60118684fc32b65ce70ccfc009e07b7e6a3cd (diff) | |
| download | puppet-938b91894d09ea804d2fc9eaac57b52f46de793a.tar.gz puppet-938b91894d09ea804d2fc9eaac57b52f46de793a.tar.xz puppet-938b91894d09ea804d2fc9eaac57b52f46de793a.zip | |
Adding cache support to indirection. If you have
a '<indirection>_cache' setting, then the indirection
will use the value there as the name of the cache.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/indirector/indirection.rb | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb index 8afe0012d..9cc116e40 100644 --- a/lib/puppet/indirector/indirection.rb +++ b/lib/puppet/indirector/indirection.rb @@ -15,9 +15,36 @@ class Puppet::Indirector::Indirection attr_accessor :name, :model - # Clear our cached list of termini. + # Create and return our cache terminus. + def cache + terminus(cache_name) + end + + # Should we use a cache? + def cache? + cache_name ? true : false + end + + # Figure out the cache name, if there is one. If there's no name, then + # caching is disabled. + def cache_name + unless @cache_name + setting_name = "%s_cache" % self.name + if ! Puppet.settings.valid?(setting_name) or (value = Puppet.settings[setting_name] and value == "none") + @cache_name = nil + else + @cache_name = value + @cache_name = @cache_name.intern if @cache_name.is_a?(String) + end + end + @cache_name + end + + # Clear our cached list of termini, and reset the cache name + # so it's looked up again. # This is only used for testing. def clear_cache + @cache_name = nil @termini.clear end @@ -38,6 +65,7 @@ class Puppet::Indirector::Indirection end @termini = {} @terminus_types = {} + @cache_name = nil raise(ArgumentError, "Indirection %s is already defined" % @name) if @@indirections.find { |i| i.name == @name } @@indirections << self end @@ -66,6 +94,7 @@ class Puppet::Indirector::Indirection end def destroy(*args) + cache.destroy(*args) if cache? terminus.destroy(*args) end @@ -75,6 +104,7 @@ class Puppet::Indirector::Indirection # these become instance methods def save(*args) + cache.save(*args) if cache? terminus.save(*args) end |
