Class: HaveAPI::Fs::Components::CacheStats

Inherits:
File show all
Defined in:
lib/haveapi/fs/components/cache_stats.rb

Instance Attribute Summary

Attributes inherited from HaveAPI::Fs::Component

#atime, #context, #ctime, #mtime

Instance Method Summary collapse

Methods inherited from File

#file?, #raw_close, #raw_open, #raw_read, #raw_sync, #raw_truncate, #raw_write, #size, #write

Methods inherited from HaveAPI::Fs::Component

#abspath, #bound=, #bound?, children_reader, component, #contents, #directory?, #executable?, #file?, #find, inherited, #initialize, #invalid?, #invalidate, #parent, #path, #readable?, #reset, #setup, #times, #title, #unsaved?, #use, #writable?

Constructor Details

This class inherits a constructor from HaveAPI::Fs::Component

Instance Method Details

#readObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/haveapi/fs/components/cache_stats.rb', line 3

def read
  c = context.cache

  {
      size: c.size,
      hits: c.hits,
      misses: c.misses,
      invalid: c.invalid,
      drops: c.drops,
      hitratio: (c.hits.to_f / (c.hits + c.misses + c.invalid) * 100).round(2),
      sweeps: c.runs,
      last_sweep: (c.last_time && c.last_time.iso8601) || '-',
      next_sweep: c.next_time.iso8601,
  }.map { |k, v| sprintf('%-15s %s', "#{k}:", v) }.join("\n") + "\n"
end