def get_fact(fact=nil)
config = Config.instance
cache_time = config.fact_cache_time || 300
Thread.exclusive do
begin
if (Time.now.to_i - @last_facts_load > cache_time.to_i ) || force_reload?
Log.debug("Resetting facter cache, now: #{Time.now.to_i} last-known-good: #{@last_facts_load}")
tfacts = load_facts_from_source
raise "Got empty facts" if tfacts.empty?
@facts = normalize_facts(tfacts)
@last_good_facts = @facts.clone
@last_facts_load = Time.now.to_i
else
Log.debug("Using cached facts now: #{Time.now.to_i} last-known-good: #{@last_facts_load}")
end
rescue Exception => e
Log.error("Failed to load facts: #{e.class}: #{e}")
@last_facts_load = Time.now.to_i
@facts = @last_good_facts.clone
end
end
if fact.nil?
return @facts
else
@facts.include?(fact) ? @facts[fact] : nil
end
end