Class: XCCache::Cache::Cachemap

Inherits:
JSONRepresentable show all
Defined in:
lib/xccache/cache/cachemap.rb

Instance Attribute Summary

Attributes inherited from HashRepresentable

#path, #raw

Instance Method Summary collapse

Methods inherited from JSONRepresentable

#load, #save

Methods inherited from HashRepresentable

#[], #[]=, #initialize, #load, #merge!, #save

Constructor Details

This class inherits a constructor from XCCache::HashRepresentable

Instance Method Details

#cache_dataObject



10
11
12
# File 'lib/xccache/cache/cachemap.rb', line 10

def cache_data
  raw["cache"] ||= {}
end

#depgraph_dataObject



6
7
8
# File 'lib/xccache/cache/cachemap.rb', line 6

def depgraph_data
  raw["depgraph"] ||= {}
end

#get_cache_data(type) ⇒ Object



51
52
53
# File 'lib/xccache/cache/cachemap.rb', line 51

def get_cache_data(type)
  cache_data.select { |_, v| v == type }.keys
end

#manifest_dataObject



14
15
16
17
18
19
20
# File 'lib/xccache/cache/cachemap.rb', line 14

def manifest_data
  raw["manifest"] ||= {
    "targets" => {},
    "deps" => {},
    "macros" => {},
  }
end

#missedObject



26
27
28
# File 'lib/xccache/cache/cachemap.rb', line 26

def missed
  get_cache_data(:missed)
end

#missed?(name) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/xccache/cache/cachemap.rb', line 22

def missed?(name)
  missed.include?(name)
end


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/xccache/cache/cachemap.rb', line 38

def print_stats
  hit, missed, ignored = i[hit missed ignore].map { |type| get_cache_data(type) }
  total_count = cache_data.count
  UI.message "    -------------------------------------------------------------------\n    Cache stats\n    \u2022 Hit (\#{hit.count}/\#{total_count}): \#{hit.to_s.green.dark}\n    \u2022 Missed (\#{missed.count}/\#{total_count}): \#{missed.to_s.yellow.dark}\n    \u2022 Ignored (\#{ignored.count}/\#{total_count}): \#{ignored.to_s.yellow.dark}\n    -------------------------------------------------------------------\n  DESC\nend\n"

#statsObject



30
31
32
33
34
35
36
# File 'lib/xccache/cache/cachemap.rb', line 30

def stats
  i[hit missed ignored].to_h do |type|
    count, total_count = get_cache_data(type).count, cache_data.count
    percent = total_count.positive? ? (count.to_f * 100 / total_count).round : 0
    [type, "#{percent}% (#{count}/#{total_count})"]
  end
end