Class: Facter::CacheManager

Inherits:
Object
  • Object
show all
Defined in:
lib/facter/framework/core/cache_manager.rb

Instance Method Summary collapse

Constructor Details

#initializeCacheManager

Returns a new instance of CacheManager.



5
6
7
8
9
10
# File 'lib/facter/framework/core/cache_manager.rb', line 5

def initialize
  @groups = {}
  @log = Log.new(self)
  @fact_groups = Facter::FactGroups.new
  @cache_dir = LegacyFacter::Util::Config.facts_cache_dir
end

Instance Method Details

#cache_facts(resolved_facts) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/facter/framework/core/cache_manager.rb', line 29

def cache_facts(resolved_facts)
  return unless Options[:cache] && Options[:ttls].any?

  @groups = {}
  resolved_facts.each do |fact|
    cache_fact(fact)
  end

  begin
    write_cache unless @groups.empty?
  rescue Errno::EACCES => e
    @log.warn("Could not write cache: #{e.message}")
  end
end

#fact_cache_enabled?(fact_name) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/facter/framework/core/cache_manager.rb', line 44

def fact_cache_enabled?(fact_name)
  fact = @fact_groups.get_fact(fact_name)
  cached = if fact
             !fact[:ttls].nil?
           else
             false
           end

  # fact_group = @fact_groups.get_fact_group(fact_name)
  # delete_cache(fact_group) if fact_group && !cached
  cached
end

#resolve_facts(searched_facts) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/facter/framework/core/cache_manager.rb', line 12

def resolve_facts(searched_facts)
  return searched_facts, [] if (!File.directory?(@cache_dir) || !Options[:cache]) && Options[:ttls].any?

  facts = []
  searched_facts.delete_if do |fact|
    res = resolve_fact(fact)
    if res
      facts << res
      true
    else
      false
    end
  end

  [searched_facts, facts.flatten]
end