Class: RecordCache::Statistics::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/record_cache/statistics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCounter

Returns a new instance of Counter.



49
50
51
# File 'lib/record_cache/statistics.rb', line 49

def initialize
  reset!
end

Instance Attribute Details

#callsObject

Returns the value of attribute calls.



47
48
49
# File 'lib/record_cache/statistics.rb', line 47

def calls
  @calls
end

#hitsObject

Returns the value of attribute hits.



47
48
49
# File 'lib/record_cache/statistics.rb', line 47

def hits
  @hits
end

#missesObject

Returns the value of attribute misses.



47
48
49
# File 'lib/record_cache/statistics.rb', line 47

def misses
  @misses
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/record_cache/statistics.rb', line 68

def active?
  RecordCache::Statistics.active?
end

#add(queried, found) ⇒ Object

add hit statatistics for the given cache strategy

Parameters:

  • queried:

    nr of ids queried

  • found:

    nr of records found in the cache



56
57
58
59
60
# File 'lib/record_cache/statistics.rb', line 56

def add(queried, found)
  @calls += 1
  @hits += found
  @misses += (queried - found)
end

#inspectObject



77
78
79
# File 'lib/record_cache/statistics.rb', line 77

def inspect
  "#{percentage}% (#{@hits}/#{@hits + @misses})"
end

#percentageObject



72
73
74
75
# File 'lib/record_cache/statistics.rb', line 72

def percentage
  return 0.0 if @hits == 0
  (@hits.to_f / (@hits + @misses)) * 100
end

#reset!Object



62
63
64
65
66
# File 'lib/record_cache/statistics.rb', line 62

def reset!
  @hits = 0
  @misses = 0
  @calls = 0
end