Class: LogBench::Log::CacheEntry

Inherits:
Entry
  • Object
show all
Defined in:
lib/log_bench/log/cache_entry.rb

Constant Summary collapse

SQL_OPERATIONS =
%w[SELECT INSERT UPDATE DELETE].freeze

Instance Attribute Summary

Attributes inherited from Entry

#content, #raw_line, #request_id, #timestamp, #timing, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entry

#http_request?, parseable?, #related_log?

Constructor Details

#initialize(raw_line) ⇒ CacheEntry



8
9
10
11
# File 'lib/log_bench/log/cache_entry.rb', line 8

def initialize(raw_line)
  super
  self.type = :cache
end

Class Method Details

.build(raw_line) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/log_bench/log/cache_entry.rb', line 13

def self.build(raw_line)
  return unless parseable?(raw_line)

  entry = Entry.new(raw_line)
  return unless entry.type == :cache

  new(raw_line)
end

Instance Method Details

#duration_msObject



22
23
24
25
26
# File 'lib/log_bench/log/cache_entry.rb', line 22

def duration_ms
  return 0.0 unless timing

  timing.gsub(/[()ms]/, "").to_f
end

#hit?Boolean



28
29
30
# File 'lib/log_bench/log/cache_entry.rb', line 28

def hit?
  content.include?("CACHE")
end

#miss?Boolean



32
33
34
# File 'lib/log_bench/log/cache_entry.rb', line 32

def miss?
  !hit?
end

#to_hObject



36
37
38
39
40
41
42
43
44
# File 'lib/log_bench/log/cache_entry.rb', line 36

def to_h
  super.merge(
    content: content,
    timing: timing,
    operation: operation,
    duration_ms: duration_ms,
    hit: hit?
  )
end