summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/util/cacher.rb9
-rwxr-xr-xspec/unit/util/cacher.rb15
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/puppet/util/cacher.rb b/lib/puppet/util/cacher.rb
index c1b3bad7a..a9fb890c6 100644
--- a/lib/puppet/util/cacher.rb
+++ b/lib/puppet/util/cacher.rb
@@ -59,7 +59,14 @@ module Puppet::Util::Cacher
# Methods that get added to instances.
module InstanceMethods
def expire
- expirer.expire
+ # Only expire if we have an expirer. This is
+ # mostly so that we can comfortably handle cases
+ # like Puppet::Type instances, which use their
+ # catalog as their expirer, and they often don't
+ # have a catalog.
+ if e = expirer
+ e.expire
+ end
end
def expirer
diff --git a/spec/unit/util/cacher.rb b/spec/unit/util/cacher.rb
index 3e8d31a24..5a867c6c1 100755
--- a/spec/unit/util/cacher.rb
+++ b/spec/unit/util/cacher.rb
@@ -79,6 +79,21 @@ describe Puppet::Util::Cacher do
@object.instance_cache.should_not equal(value)
end
+ it "should be able to trigger expiration on its expirer" do
+ @expirer.expects(:expire)
+ @object.expire
+ end
+
+ it "should do nothing when asked to expire when no expirer is available" do
+ cacher = CacheTest.new
+ class << cacher
+ def expirer
+ nil
+ end
+ end
+ lambda { cacher.expire }.should_not raise_error
+ end
+
it "should be able to cache false values" do
@object.expects(:init_instance_cache).returns false
@object.instance_cache.should be_false