Class: Counters::Memory

Inherits:
Base
  • Object
show all
Defined in:
lib/counters/memory.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#namespace

Instance Method Summary collapse

Methods inherited from Base

#hit, #latency, #magnitude, #ping

Constructor Details

#initialize(options = {}) ⇒ Memory

Returns a new instance of Memory.



7
8
9
10
11
12
13
14
# File 'lib/counters/memory.rb', line 7

def initialize(options={})
  super(options)

  @hits       = Hash.new {|h,k| h[k] = 0}
  @magnitudes = Hash.new {|h,k| h[k] = 0}
  @latencies  = Hash.new {|h,k| h[k] = Array.new}
  @pings      = Hash.new
end

Instance Attribute Details

#hitsObject (readonly)

Returns the value of attribute hits.



5
6
7
# File 'lib/counters/memory.rb', line 5

def hits
  @hits
end

#latenciesObject (readonly)

Returns the value of attribute latencies.



5
6
7
# File 'lib/counters/memory.rb', line 5

def latencies
  @latencies
end

#magnitudesObject (readonly)

Returns the value of attribute magnitudes.



5
6
7
# File 'lib/counters/memory.rb', line 5

def magnitudes
  @magnitudes
end

#pingsObject (readonly)

Returns the value of attribute pings.



5
6
7
# File 'lib/counters/memory.rb', line 5

def pings
  @pings
end

Instance Method Details

#record_hit(key) ⇒ Object



16
17
18
# File 'lib/counters/memory.rb', line 16

def record_hit(key)
  @hits[key] += 1
end

#record_latency(key, time_in_seconds) ⇒ Object



24
25
26
# File 'lib/counters/memory.rb', line 24

def record_latency(key, time_in_seconds)
  @latencies[key] << time_in_seconds
end

#record_magnitude(key, value) ⇒ Object



28
29
30
# File 'lib/counters/memory.rb', line 28

def record_magnitude(key, value)
  @magnitudes[key] = value
end

#record_ping(key) ⇒ Object



20
21
22
# File 'lib/counters/memory.rb', line 20

def record_ping(key)
  @pings[key] = Time.now.utc
end