module RecordCache::Statistics
Collect cache hit/miss statistics for each cache strategy
Public Class Methods
active?()
click to toggle source
returns true
if statistics need to be collected
# File lib/record_cache/statistics.rb, line 9 def active? !!@active end
find(base = nil, attribute = nil)
click to toggle source
Retrieve the statistics for the given base and attribute Returns a hash {<attribute> => <statistics} for a model if no strategy is provided Returns a hash of hashes { <model_name> => {<attribute> => <statistics} } if no parameter is provided
# File lib/record_cache/statistics.rb, line 38 def find(base = nil, attribute = nil) stats = (@stats ||= {}) stats = (stats[base.name] ||= {}) if base stats = (stats[attribute] ||= Counter.new) if attribute stats end
reset!(base = nil)
click to toggle source
reset all statistics
# File lib/record_cache/statistics.rb, line 29 def reset!(base = nil) stats = find(base).values stats = stats.map(&:values).flatten unless base # flatten hash of hashes in case base was nil stats.each{ |s| s.reset! } end
start()
click to toggle source
start statistics collection
# File lib/record_cache/statistics.rb, line 14 def start @active = true end
stop()
click to toggle source
stop statistics collection
# File lib/record_cache/statistics.rb, line 19 def stop @active = false end
toggle()
click to toggle source
toggle statistics collection
# File lib/record_cache/statistics.rb, line 24 def toggle @active = !@active end