Allowing a nil expirer for caching classes.

If there's no expirer, then the value is regenerated every
time.

Signed-off-by: Luke Kanies <luke@madstop.com>
This commit is contained in:
Luke Kanies 2008-11-11 13:01:14 -08:00
Родитель cd09d6b90d
Коммит 29b97943e7
2 изменённых файлов: 8 добавлений и 2 удалений

Просмотреть файл

@ -70,7 +70,8 @@ module Puppet::Util::Cacher
end
def cached_value(name)
if expirer.expired?(cache_timestamp)
# Allow a nil expirer, in which case we regenerate the value every time.
if expirer.nil? or expirer.expired?(cache_timestamp)
value_cache.clear
@cache_timestamp = Time.now
end

Просмотреть файл

@ -51,7 +51,7 @@ describe Puppet::Util::Cacher do
CacheTest.new.expirer.should equal(Puppet::Util::Cacher)
end
describe "when defining cached attributes" do
describe "when using cached attributes" do
before do
@expirer = ExpirerTest.new
@object = CacheTest.new
@ -90,5 +90,10 @@ describe Puppet::Util::Cacher do
@expirer.expire
@object.instance_cache.should equal(@object.instance_cache)
end
it "should always consider a value expired if it has no expirer" do
@object.stubs(:expirer).returns nil
@object.instance_cache.should_not equal(@object.instance_cache)
end
end
end