Class: RecordCache::Statistics::Counter
- Inherits:
-
Object
- Object
- RecordCache::Statistics::Counter
- Defined in:
- lib/record_cache/statistics.rb
Instance Attribute Summary collapse
-
#calls ⇒ Object
Returns the value of attribute calls.
-
#hits ⇒ Object
Returns the value of attribute hits.
-
#misses ⇒ Object
Returns the value of attribute misses.
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#add(queried, found) ⇒ Object
add hit statatistics for the given cache strategy.
-
#initialize ⇒ Counter
constructor
A new instance of Counter.
- #inspect ⇒ Object
- #percentage ⇒ Object
- #reset! ⇒ Object
Constructor Details
#initialize ⇒ Counter
Returns a new instance of Counter.
49 50 51 |
# File 'lib/record_cache/statistics.rb', line 49 def initialize reset! end |
Instance Attribute Details
#calls ⇒ Object
Returns the value of attribute calls.
47 48 49 |
# File 'lib/record_cache/statistics.rb', line 47 def calls @calls end |
#hits ⇒ Object
Returns the value of attribute hits.
47 48 49 |
# File 'lib/record_cache/statistics.rb', line 47 def hits @hits end |
#misses ⇒ Object
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
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
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 |
#inspect ⇒ Object
77 78 79 |
# File 'lib/record_cache/statistics.rb', line 77 def inspect "#{percentage}% (#{@hits}/#{@hits + @misses})" end |
#percentage ⇒ Object
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 |